dpkk8687 2014-03-18 20:50
浏览 8
已采纳

MySQL UPDATE查询问题

I have a super easy question. I have a form that echoes out a mySQL record that the user can update. I make my changes, and it tells me that the update is successful, but when I look at the table, the changes do not go through. What is the problem here?

This is the first script.

<?php
require_once("models/config.php");
?>

<table border=1>
 <tr>
<td align=center>Edit Form</td>
  </tr>
  <tr>
   <td>
  <table>
  <?
  $personid=$_SERVER['QUERY_STRING'];

  $order = "SELECT * FROM persons where personid='$personid'";

  $result = mysqli_query($mysqli,$order);
  $row = mysqli_fetch_array($result);
  ?>
  <form method="post" action="edit_data.php">
  <input type="hidden" name="id" value="<? echo "$row[personid]"?>"> 
  <tr>Person ID:<? echo "$row[personid]"?></tr>
    <tr>        
      <td>First Name</td>
      <td>
        <input type="text" name="firstname" 
    size="20" value="<? echo "$row[firstname]"?>">
      </td>
    </tr>
    <tr>
      <td>Surname</td>
      <td>
        <input type="text" name="surname" size="40" 
      value="<? echo "$row[surname]"?>">
      </td>
    </tr>
    <tr>
      <td align="right">
        <input type="submit" 
      name="submit value" value="Edit">
      </td>
    </tr>
     </form>
    </table>
    </td>
 </tr>
  </table>
  </body>
  </html>

Which then goes through to this:

<?
require_once("models/config.php");

 $personid = $_POST['personid'];
 $firstname = mysqli_real_escape_string($mysqli, htmlspecialchars($_POST['firstname']));
 $surname = mysqli_real_escape_string($mysqli, htmlspecialchars($_POST['surname']));

 $order = "UPDATE persons SET firstname='$firstname', surname='$surname' WHERE   personid='$personid'";
$result = mysqli_query($mysqli,$order);
 if (!$result) {
echo "Error entering data! <BR>";
echo mysql_error();
} else {
echo "User updated to $firstname $surname <BR>";
}
?>

Is there something I am missing here?

Thanks in advance.

  • 写回答

3条回答 默认 最新

  • dongyiluan1718 2014-03-18 20:54
    关注

    You are sending a hidden input named id and trying to use a $_POST['personid'] correct that

    You may also pay attention to the comments you had (SQL Injection's one at least)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上