samedi 19 septembre 2020

"how to assign a globule variable if isset"

using ajax i echo the value . now i want to add that value in to a globule variable

view.php

  <script>
    $('#subval').click(function(){

    var uname = $('#userid1').val();
    alert(uname);
   
    $.ajax({
    url:'test.php',
     data:'user=' + uname,
      success: function(data){
      $('#uuid').html(data);
     
     }


    });

    });
    </script>

test.php

 <p id="uuid"></p>

 if(isset($_GET['user'])){
   
   echo $_GET['user'];                                           
      }
      

out put is success value 68 now i want to assign this value to globule variable

<?php
   
    if(isset($_GET['user'])){

            global $iduu;
            echo $_GET['user'];
            $iduu = $_GET['user'];
           
    }                  
        
    $unam1 = '';
    $sql = "SELECT * FROM user WHERE id='$iduu'";
    $result = mysqli_query($conn, $sql);
    if(mysqli_num_rows($result) > 0)
    {
        while($row = mysqli_fetch_assoc($result))
        {
            $unam1 = $row["uname"];
        
        }
    }
?>

i got an error Notice: Undefined variable: iduu in C:\wamp64\www\abrar\view.php\test.php on line 33

Aucun commentaire:

Enregistrer un commentaire