gpt4 book ai didi

PHP 更新查询不起作用

转载 作者:行者123 更新时间:2023-11-30 01:24:30 29 4
gpt4 key购买 nike

作为我的老师给我(高中 10 年)的一项任务,使用 html 和 php 创建登录表单,因为我们刚刚开始学习 PHP,我已经取得了进步,这是我的第一次尝试。稍后我将讨论更安全的选项。

<?PHP

//Create the connection…
//("where the database is", 'Database login' , 'database password' , "Database name")
$con=mysqli_connect("", 'root', 'root', "Social");

//Check our connection…
if (mysqli_connect_errno($con))
{
echo " Sorry Mate";
}
$username = $_POST[username];
$password = $_POST[pawd];

$result = mysqli_query($con, "SELECT * FROM User_info");
$row = mysqli_fetch_array($result);
$value = $row['username'];
if($value == "$username")
{
$result = mysqli_query($con, "SELECT * FROM User_info");
$row = mysqli_fetch_array($result);
$value = $row['password'];
if($value == "$password")
{
$sql=("UPDATE user_check SET user = '1' ");
$sql=("UPDATE user_check SET name = '$username' ");
header( 'Location: feed.php' ) ;
}
else
{
header( 'Location: social.php' ) ;
}
}
else
{
header( 'Location: social.php' ) ;
}

if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
?>

它说的地方

        $sql=("UPDATE user_check SET user = '1' ");
$sql=("UPDATE user_check SET name = '$username' ");

第一个可以工作并将数据库更新为 1,但是第二个没有,我检查了列的名称,更改了变量 $sql 和 $username 的名称,但它仍然无法工作,是否有任何问题建议?预先感谢您:D

最佳答案

您首先将 $_POST['username'] 与结果中的 username 列进行比较,然后尝试更新 name数据库中的列。我的猜测是:

$sql = ("UPDATE user_check SET name = '$username' ");

应该是:

$sql = ("UPDATE user_check SET username = '$username' ");

关于PHP 更新查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18169164/

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