运行这段代码时存在一定问题,如图。
<?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";?>

解决方案 »

  1.   

    全部是一些没有定义的变量$subject1、$id、$teacher1...另外,同一条件的update 语句可以写在一起。执行一次就够了。
      

  2.   


    那我这样写对不对? $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);我应该在哪怎么定义变量?
      

  3.   

    上面的语句的对的你的变量是通过表单提交过来的吧? 那就 $subject1=$_POST['subject1'] ;
      

  4.   

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

  5.   

    在哪个位置定义变量呢?
    是这样定义的 $subject1=$_POST['subject1'] ; 吗?
      

  6.   

    你贴出的代码的第 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'";就可以了,其他都不要动
    以后遇到类似的情况都这样做
      

  7.   

    Notice: Undefined variable: xxx
    注意:未定义的变量: xxx再新的手,也得会借助翻译看懂错误信息!