读书人

为何修改信息后数据库表中内容为空

发布时间: 2013-06-19 10:26:41 作者: rapoo

为什么修改信息后数据库表中内容为空
套用上一套修改课题的代码写了一个修改信息的代码,但是将内容修改提交后,再查询表中内容发现除了xuehao其他内容为空?

<?php
//######################学生信息修改1##########################
include "config.php";
include "header.php";
?>
<title>修改学生信息</title>
<?php
extract($_REQUEST);
$query="update $student_table set name='$name1' where xuehao='$xuehao'";
mysql_query("set names 'GB2312'");
$result=mysql_query($query);
$query="update $student_table set sex='$sex1' where xuehao='$xuehao'";
mysql_query("set names 'GB2312'");
$result=mysql_query($query);
$query=mysql_query("update $student_table set class='$class1' where xuehao='$xuehao'");
mysql_query("set names 'GB2312'");
$result=mysql_query($query);
$query=mysql_query("update $student_table set password='$password2' where xuehao='$xuehao'");
mysql_query("set names 'GB2312'");
$result=mysql_query($query);
$query=mysql_query("update $student_table set password1='$password3' where xuehao='$xuehao'");
mysql_query("set names 'GB2312'");
$result=mysql_query($query);
$query="update $student_table set love='$love1' where xuehao='$xuehao'";
mysql_query("set names 'GB2312'");
$result=mysql_query($query);
$query="update $student_table set telephone='$telephone1' where xuehao='$xuehao'";
mysql_query("set names 'GB2312'");
$result=mysql_query($query);
$query="update $student_table set reward='$reward1' where xuehao='$xuehao'";
mysql_query("set names 'GB2312'");
$result=mysql_query($query);

if($password2!=$password3)
{
echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>输入的密码不一致,请重新输入。</big></b></font></p>";
echo "<meta http-equiv=\"refresh\" content=\"2;url=alter_student1.php\">";
exit;
}

if($result==true)
{
echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>修改信息成功!</big></b></font>";
echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">";
exit;
}
else
{
echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>修改出错,请返回重新修改。</big></b></font></p>";
echo "<meta http-equiv=\"refresh\" content=\"1;url=alter_student.php\">";
exit;
}


?>
<?php include "foot.php";?>


[解决办法]
print_r($_REQUEST);
贴出结果

if($password2!=$password3)
{
echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>输入的密码不一致,请重新输入。</big></b></font></p>";
echo "<meta http-equiv=\"refresh\" content=\"2;url=alter_student1.php\">";
exit;
}
应放在修改数据的代码之前

所有的修改数据指令宜合并在一起
并在实行时加入排错
$result=mysql_query($query) or die(mysql_error());

php 已取消魔术转义,需注意自行对传入数据的转义处理

读书人网 >PHP

热点推荐