• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

如何修改数据库中内容

php 搞代码 3年前 (2022-01-23) 24次浏览 已收录 0个评论
文章目录[隐藏]

运行这段代码时存在一定问题,如图。

<?php//######################修改课题界面3##########################  include "config.php";  include "admin_header.php";?> <title>修改课题</title><?php   $query="update $jiaoshi_table set subject='$subject1' where id='$id'";   mysql_query("set names 'GB2312'");   $result=mysql_query($query);   $query="update $jiaoshi_table set teacher='$teacher1' where id='$id'";   mysql_query("set names 'GB2312'");   $result=mysql_query($query);   $query=mysql_query("update $jiaoshi_table set zhicheng='$zhicheng1' where id='$id'");   mysql_query("set names 'GB2312'");   $result=mysql_query($query);   $query=mysql_qu<strong style="color:transparent">9来源gaodai#ma#com搞@代~码$网</strong>搞gaodaima代码ery("update $jiaoshi_table set specialized='$specialized1' where id='$id'");   mysql_query("set names 'GB2312'");   $result=mysql_query($query);   $query=mysql_query("update $jiaoshi_table set code='$select' where id='$id'");   mysql_query("set names 'GB2312'");   $result=mysql_query($query);    $query="update $jiaoshi_table set beizhu='$introduction' where id='$id'";   mysql_query("set names 'GB2312'");   $result=mysql_query($query);      $query="select number as sn,surplus as ssn from $jiaoshi_table where id='$id'";		mysql_query("set names 'GB2312'");		$result=mysql_query($query);		$row=mysql_fetch_array($result);		if($number1<$row[sn])		{			if($number1<($row[sn]-$row[ssn]))			{				echo"<p align="center"><font color="#FF0000"><b><big>人数不能少于现已选题人数,人数列修改失败!</big></b></font>";				echo"<meta http-equiv=\"refresh\" content=\"2;url=alter_keti.php\">";				exit;			}			else			{		    	$query2=mysql_query("update $jiaoshi_table set number='$number1' where id='$id'");				$query3=mysql_query("update $jiaoshi_table set surplus=surplus-($row[sn]-$number1) where id='$id'");				mysql_query("set names 'GB2312'");   				$result1=mysql_query($query3);							}		}		else		{			$query4=mysql_query("update $jiaoshi_table set number='$number1' where id='$id'");			$query5=mysql_query("update $jiaoshi_table set surplus=surplus+($number1-$row[sn]) where id='$id'");			mysql_query("set names 'GB2312'");   			$result2=mysql_query($query5);			   		}				if($result==true)				{				   echo"<p align="center"><font color="#FF0000"><b><big>修改课题成功!</big></b></font>";				   echo "<meta http-equiv=\"refresh\" content=\"1;url=alter_keti.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_keti.php\">"; 				   exit;				 }		?><?php include "foot.php";?>

回复讨论(解决方案)

全部是一些没有定义的变量$subject1、$id、$teacher1…

另外,同一条件的update 语句可以写在一起。执行一次就够了。

全部是一些没有定义的变量$subject1、$id、$teacher1…

另外,同一条件的update 语句可以写在一起。执行一次就够了。

那我这样写对不对?

 $query="update $jiaoshi_table set subject='$subject1',teacher='$teacher1',zhicheng='$zhicheng1',specialized='$specialized1' , code='$select',beizhu='$introduction'where id='$id'";   mysql_query("set names 'GB2312'");   $result=mysql_query($query);

我应该在哪怎么定义变量?

上面的语句的对的

你的变量是通过表单提交过来的吧? 那就 $subject1=$_POST[‘subject1’] ;

<?php
extract($_REQUEST); //加上这句
$query=”update $jiaoshi_table set subject=’$subject1′ where id=’$id'”;
….

<?php
extract($_REQUEST); //加上这句
$query=”update $jiaoshi_table set subject=’$subject1′ where id=’$id'”;
…. 在哪个位置定义变量呢?
是这样定义的 $subject1=$_POST[‘subject1’] ; 吗?

你贴出的代码的第 7、8 行不是这样吗
<?php
$query=”update $jiaoshi_table set subject=’$subject1′ where id=’$id'”;
把他改成这样
<?php
extract($_REQUEST); //加上这句
$query=”update $jiaoshi_table set subject=’$subject1′ where id=’$id'”;

就可以了,其他都不要动
以后遇到类似的情况都这样做

Notice: Undefined variable: xxx
注意:未定义的变量: xxx

再新的手,也得会借助翻译看懂错误信息!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何修改数据库中内容

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址