0

这是我的代码无法正常工作

 <?php
 include('admin/class.php');

这是我的数据库连接:

 $hostname="localhost";
 $username="root";
 $password="";
 $dbhandle = mysql_connect($hostname, $username, $password)
 or die("Unable to connect to MySQL");
 echo "Connected to MySQL<br>"; 
 $se = mysql_select_db("timesheet1234",$dbhandle)
   or die("Could not select timesheet1234");
 echo "connected to db";

单击按钮后,这里正在执行功能:

 if(isset($_POST['save']))
 {  
 $sel=@$_POST['selpro'];
 $mon=@$_POST['mon'];
 $tue=@$_POST['tue'];
 $wed=@$_POST['wed'];
 $thu=@$_POST['thu'];
 $fri=@$_POST['fri'];
 $sat=@$_POST['sat'];
 $sun=@$_POST['sun'];

这里正在编写查询功能

 if(isset($_SESSION['user']))
 {
 echo "session user";
 $sql="UPDATE empdaytimesheet SET 
`project code`='$sel',`mon`='$mon',`tue`='$tue',`wed`='$wed',`thu`='$thu',`
 fri`='$fri',`sat`='$sat',`sun`='$sun' where `username`='".$_SESSION['user']."'";

 $res=mysql_query($sql,$dbhandle);

这是它不起作用的问题:

    if($res){
         echo "<script type='text/javascript'>";
         echo "alert('TimeSheet Saved..!')";
         echo "</script>";
         echo "<script type='text/javascript'>";
         echo "window.location='my_timesheet.php'";
         echo "</script>";
      }
      else
      {
         echo "<script type='text/javascript'>";
         echo "alert('Some Error Occured ! Retry..!')";
         echo "</script>";
         echo "<script type='text/javascript'>";
         echo "window.location='my_timesheet.php'";
         echo "</script>";
      }
    }
  }
?>
4

1 回答 1

0

删除 $_POST 之前的“@”,你应该没问题。

但是,您当前的脚本看起来很容易受到 SQLi 的攻击。

而且您还使用了已弃用的扩展程序。您应该考虑改用 MySQLi 或 PDO。

查看此答案以获取有关如何使您的代码更安全的更多信息。

于 2013-05-11T12:43:31.413 回答