[英]entered form data is not saving in mysql db?
Here is my code which is not working properly 这是我的代码,无法正常工作
<?php
include('admin/class.php');
Here is my db connection: 这是我的数据库连接:
$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";
Here am doing the functionality after clicking the button: 单击按钮后,即可执行以下功能:
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'];
Here am writing the query functionality 在这里写查询功能
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);
Here is the problem where it is not working: 这是无法使用的问题:
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>";
}
}
}
?>
Remove the '@' before $_POST and you should be fine. 删除$ _POST之前的'@',就可以了。
However, your current script looks like it's vulnerable to SQLi. 但是,您当前的脚本看起来很容易受到SQLi的攻击。
And you are also using a deprecated extension. 而且您还使用了不推荐使用的扩展名。 You should consider using MySQLi or PDO instead.
您应该考虑改用MySQLi或PDO。
Check this answer on more information on how to make your code more secure. 检查此答案以获取有关如何使代码更安全的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.