如何修改数据库中内容

php中文网
发布: 2016-06-23 14:10:03
原创
1075人浏览过

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

<?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_query("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";?>
登录后复制

I-Shop购物系统
I-Shop购物系统

部分功能简介:商品收藏夹功能热门商品最新商品分级价格功能自选风格打印结算页面内部短信箱商品评论增加上一商品,下一商品功能增强商家提示功能友情链接用户在线统计用户来访统计用户来访信息用户积分功能广告设置用户组分类邮件系统后台实现更新用户数据系统图片设置模板管理CSS风格管理申诉内容过滤功能用户注册过滤特征字符IP库管理及来访限制及管理压缩,恢复,备份数据库功能上传文件管理商品类别管理商品添加/修改/

I-Shop购物系统 0
查看详情 I-Shop购物系统

回复讨论(解决方案)

全部是一些没有定义的变量$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'] ;

extract($_REQUEST); //加上这句
   $query="update $jiaoshi_table set subject='$subject1' where id='$id'";
....

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

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

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

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

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

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号