热搜:NVER node 开发 php

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

2024-09-12 13:20:01
为什么修改信息后数据库表中内容为空

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

<?php//######################学生信息修改1##########################  include "config.php";  include "header.php";?> 修改学生信息<?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"

输入的密码不一致,请重新输入。

"; echo ""; exit; } if($result==true) { echo"

修改信息成功!"; echo ""; exit; } else { echo"

修改出错,请返回重新修改。

"; echo ""; exit; } ?><?php include "foot.php";?>


回复讨论(解决方案)

悲剧啊,都没有人回答我的问题……

print_r($_REQUES); 看看

extract($_REQUEST);
看下你这个函数。先把变量打印出来看看值是不是空的。如果不是再说别的,我觉得很有可能是你表单哪个字母打错了。

表示数据库更新处理不合理,没有必要每次都set names

print_r($_REQUEST);
贴出结果

if($password2!=$password3)
{
echo"

输入的密码不一致,请重新输入。

";
echo "";
exit;
}
应放在修改数据的代码之前

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

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

print_r($_REQUEST);
贴出结果

if($password2!=$password3)
{
echo"

输入的密码不一致,请重新输入。

";
echo "";
exit;
}
应放在修改数据的代码之前

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

php 已取消魔术转义,需注意自行对传入数据的转义处理 结果是这样的,我查了一下,表还是为空。是不是我的代码本身就有问题?

因为你变量未赋值啊

因为你变量未赋值啊 能告诉我一下在哪个位置赋值,怎样赋值吗?我是新手……

print_r($_REQUEST);
贴出结果

if($password2!=$password3)
{
echo"

输入的密码不一致,请重新输入。

";
echo "";
exit;
}
应放在修改数据的代码之前

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

php 已取消魔术转义,需注意自行对传入数据的转义处理 还有一个问题就是,为什么有的修改语句是
$query="update...
有的语句就是
$query=mysql_query("update...

$name1=$_post('表单里的名字')
没看到你那有什么获取参数



print_r($_REQUEST);
贴出结果

if($password2!=$password3)
{
echo"

输入的密码不一致,请重新输入。

";
echo "";
exit;
}
应放在修改数据的代码之前

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

php 已取消魔术转义,需注意自行对传入数据的转义处理 大哥,这是我重新改的代码
<?php//######################学生信息修改1##########################  include "config.php";  include "header.php";?> 修改学生信息<?php   extract($_REQUEST);      if($password2!=$password3)  {     echo"

输入的密码不一致,请重新输入。

"; echo ""; exit; } $query="update $student_table set name='$name1',sex='$sex1' where xuehao='$xuehao'"; mysql_query("set names 'GB2312'"); $result=mysql_query($query)or die(mysql_error()); $query=mysql_query("update $student_table set class='$class1',password='$password2',password1='$password3' where xuehao='$xuehao'"); mysql_query("set names 'GB2312'"); $result=mysql_query($query)or die(mysql_error()); $query="update $student_table set love='$love1',telephone='$telephone1', reward='$reward1' where xuehao='$xuehao'"; mysql_query("set names 'GB2312'"); $result=mysql_query($query)or die(mysql_error()); if($result==true) { echo"

修改信息成功!"; echo ""; exit; } else { echo"

修改出错,请返回重新修改。

"; echo ""; exit; } print_r($_REQUEST);?><?php include "foot.php";?>
这是运行结果,如图

我yousql直接写的不会用代码

我yousql直接写的不会用代码 什么意思?

上面提示你SQL语法有错误,上面说过了,有些变量并没有extract出来,也就是你下面用来拼接SQL的变量有的是没有定义过的,也就是空值。