gpt4 book ai didi

php - Mysql 查询在 if 子句中不接受?

转载 作者:行者123 更新时间:2023-11-29 04:47:45 26 4
gpt4 key购买 nike

这是我的 php 代码,它不能正常工作....

它不采用 if 条件下的查询,每次执行 else 部分时......

  <?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']))
{
echo "post if";

$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>";
}
}
}
?>

最佳答案

改变

$sql="UPDATE table empdaytimesheet SET project  code='$sel',...

$sql="UPDATE empdaytimesheet SET `project  code`='$sel', ...
^ no table here ^ ^ backticks

关于php - Mysql 查询在 if 子句中不接受?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16494710/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com