dongrenshi0889 2013-05-18 10:14
浏览 14

如果用户单击编辑链接,则更新表

Im trying to get my query to update upon user click This one here works but it doesnt wanna update I Says Query Empty

I edited the code as follows

  if ($action == "edit"){
if ($_SERVER['REQUEST_METHOD'] == 'POST') { 



    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $email = $_POST['email'];

    $result=mysql_query("UPDATE user SET first_name='$first_name',last_name='$last_name',email='$email' WHERE id=$id");
     $sql = mysql_query($result) or die (mysql_error());
}

$sql=mysql_query("select * from user where id='$id'");

while ($row=mysql_fetch_array($sql)){                                             
    $id = $row['id'];
    $first_name = $row['first_name'];
    $last_name = $row['last_name'];
    $email = $row['email'];


    echo("<form name='edit' method='post' action='?action=edit'>");
    echo("<input type='hidden' name='?action=edit'>");
    echo("<table class=main cellspacing=0 cellpadding=5 >");
    echo("<tr><td>Name: </td><td align='right'><input type='text' name='first_name' value='$first_name'></td></tr>");
    echo("<tr><td>Surname: </td><td align='right'><input type='text'  name='last_name' value='$last_name'></td></tr>");
    echo("<tr><td>Email: </td><td align='right'><input type='text' name='email' value='$email'></td></tr>");
    echo("<tr><td></td><td><div align='right'><input type='submit'></div></td></tr>");
    echo("</table>");
}
       }  


echo("<br>");                                                                                                                                                                                                                                                                                                               
echo("</form>");

I added $sql = mysql_query($result) or die (mysql_error());

the above line shows what time of error the query encounted while executing... Any Ideas as to why the query is empty and wheres there is data in the table?

This Code will run upon the clicking of this link

echo"<a href='test.php?action=edit&id=$id'>Edit</a>";
  • 写回答

2条回答 默认 最新

  • doubengman2072 2013-05-18 10:19
    关注

    You do not catch the value of id. As you have it written in the URL, it is transmitted via GET, the rest of your data is via POST. So you either have to transmit as a POST var as well:

    <input type="hidden" name="id" value="$id"/>
    

    And catch it via PHP:

    $id = $_POST['id'];
    

    or let it the way it is and catch it as a GET-variable:

    $id = $_GET['id'];
    

    BUT: this code is horribly insecure. I advise you to search for sql injection and similar topics..

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭