2015-09-24 49 views
0

更新頁:問題在使用PHP更新表

<?php 

    mysql_connect("localhost","root","");//database connection 
    mysql_select_db("basic"); 

     $data_id = $_GET['id']; 
     $order = "select * from user where id=$data_id";  $result=mysql_query($order); 

        while($row = mysql_fetch_array($result)) 

        { 
      $fn= $row['First_name'] ;  $ln= $row['last_name'] ;  $s= $row['sex'] ;  $ad= $row['address']; } 

    ?>   <form action="form_finalupdate.php" method="GET" > 

    <fieldset> <legend>Welcome <?php echo "$fn" ?></legend> 


Update your Information:<br><br> 

    First Name: <input type="text" name="fname" value="<?php echo "$fn" 
?>" > &nbsp; Last Name: <input type="text" name ="lname" 
value="<?php echo "$ln" ?>" > <br><br> 


Sex:<br> <input type="radio" name="sex" value="male" value="<?php echo 
"$s"?>" >Male<br> <input type="radio" name="sex" value="female" 
value="<?php echo "$s" ?>" >Female<br><br> 

Address: <input type=text name="add"value="<?php echo "$ad" ?>" > 
<br><br> 


<input type="submit" value="Update" > 

</fieldset> </form> 

Finalupdate頁:

<?php 

mysql_connect("localhost","root","");//database connection 
mysql_select_db("basic"); 

     $data_id = $_GET['id']; 
      $fn= $row['First_name'] ;  $ln= $row['last_name'] ;  $s= $row['sex'] ;  $ad= $row['address']; 

     $order = "UPDATE user 
        SET First_name='$fn',last_name='$ln',sex='$s',address='$ad' 
        WHERE id='$data_id' "; 

$result=mysql_query($order);  ?> 
+0

問題是? – Drew

+0

其實我試圖更新數據庫表,並顯示值恢復正常形式。但它給最終update.php文件中的錯誤說未定義的變量:在C:\ xampp \ htdocs \ dip \ form_finalupdate.php在第8行等行...請幫我 –

+0

爲什麼他會使用set不止一次@SunilPachlangia? – Drew

回答

-1

$ data_id = $ _GET [ '身份證'];

$ fn = $ row ['First_name']; $ ln = $ row ['last_name']; $ s = $ row ['sex']; $ ad = $ row ['address'];

那麼你在「form_finalupdate.php」中沒有任何「$ row」變量。試試$ _GET。

P.S:直接向查詢傳遞數據可能會導致SQL注入。請使用糾正措施或使用PDO。