gpt4 book ai didi

php - 更新 mySQL 查询无效

转载 作者:搜寻专家 更新时间:2023-10-30 21:59:30 25 4
gpt4 key购买 nike

我一直在研究学生登录和注册类(class)的一些学生管理系统,登录机制在登录后工作正常,它显示学生姓名、ID 等并要求注册类(class),当学生选择类(class)时,所选类(class)应更新为数据库,提交页面需要从上一页获取学生ID和类(class),并相应地更新数据库。

提交后仅将类(class)更新为 $fresh :S

这是 submit.php 代码:

<?php
$dbhost = 'localhost';
$dbuser = 'username';
$dbpass = '123';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}

$fresh = $_REQUEST["fresh"];
$user_id= $_REQUEST["user_id"];


$sql = 'UPDATE courses
SET fresh="$fresh"
WHERE user_id=$user_id';

mysql_select_db('registrations');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
?>

最佳答案

试试这个 block 代码。

<?php
$dbhost = 'localhost';
$dbuser = 'username';
$dbpass = '123';
$database='registrations';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass,$database);
if (!$conn || $conn==null) die('Could not connect: ' . mysqli_error($conn));

$fresh = $_REQUEST["fresh"];
$user_id= $_REQUEST["user_id"];


$sql = "UPDATE courses
SET fresh='$fresh'
WHERE user_id=$user_id";

$retval = mysqli_query($conn, $sql);
if(! $retval )
{
die('Could not update data: ' . mysqli_error($conn));
}
else{
echo "Updated data successfully\n";
}
mysqli_close($conn);
?>

关于php - 更新 mySQL 查询无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21796509/

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