这是我的代码。在此代码中,当您使用PHP编辑和“更新”数据库中的数据时,它不会更改数据库或myphpadmin中的数据。看看下面的代码:为什么我不能使用PHP编辑/更新数据库?
<?php
include("dataconn.php"); //connect to database with the external php.
if($_SESSION["loggedin"]!="true")
header("location:admin_login.php");
$aid=$_SESSION["userid"];
$admin_info="select * from admin where AD_ID='".$aid."'";
if(isset($_POST["savebtn"]))
{
$adname=$_POST["name"];
$adaddress=$_POST["address"];
$ademail=$_POST["email"];
$adcontact=$_POST["contact"];
mysql_query("update admin set AD_NAME='".$ad_name."',ADDRESS='".$adaddress."',EMAIL='".$ademail."',CONTACT_NUM='".$adcontact."' where AD_ID=$aid");
header("location:profile.php");
}
?>
<body>
<form name="edit" method="post" action="">
<tr>
<th class="title">Name</th>
<td>:</td>
<th><input type="text" size="50" value="<?php echo $row["AD_NAME"]?>" name="name"/></th>
</tr>
<tr>
<th class="title">Address</th>
<td>:</td>
<th><input type="text" size="50" value="<?php echo $row["ADDRESS"];?>" name="address" /></th>
</tr>
<tr>
<th class="title">Email</th>
<td>:</td>
<th><input type="text" size="50" value="<?php echo $row["EMAIL"];?>" name="email"/></th>
</tr>
<tr>
<th class="title">Contact Number</th>
<td>:</td>
<th><input type="text" size="50" value="<?php echo $row["CONTACT_NUM"];?>" name="contact"></th>
</tr>
<table>
<span id="edit"><input type="submit" name="savebtn" value="SAVE/CHANGE"/></span>
</form>
</body>
</html>
我试图解决这个问题无数次,但它仍然有同样的问题。你可以帮我吗?
您是否收到错误消息?另外,查看准备好的语句,否则将会收到SQL注入攻击。 – Sablefoste
你应该是存储和检查'mysql_query'或测试没有'mysql_error'。另外,使用'PDO'语句,直接从'$ _POST'接受值并将它们放入查询中是很危险的。 –
使用mysql_error()检查是否有任何sql错误 –