gpt4 book ai didi

php - 在php中插入另一个表后如何更新表

转载 作者:行者123 更新时间:2023-11-29 20:46:36 27 4
gpt4 key购买 nike

这是我的 php 文件...我想在成功插入第二个表后更新第一个表,我要正确选择并插入,但我想要更新的行在插入数据后没有得到更新。

if($_SERVER['REQUEST_METHOD']=='POST')
{
$full_name=$_POST['full_name'];
$email_address=$_POST['email_address'];
$contact_number=$_POST['contact_number'];
$gender=$_POST['gender'];
$location=$_POST['location'];
$standard=$_POST['standard'];
$institute=$_POST['institute'];
$code=$_POST['code'];

$sql = "SELECT * FROM activations WHERE code='$code' AND status='not used'";
$check = mysqli_fetch_array(mysqli_query($conn,$sql));
if(isset($check)==null)
{
echo 'exist';
}
else
{
$sql1="INSERT INTO students(full_name, email_address, contact_number, gender, location, standard, institute) VALUES('$full_name','$email_address','$contact_number','$gender','$location','$standard','$institute')";
}
if (mysqli_query($conn, $sql1)==true)
{
$sql2="UPDATE activations SET status='in use' WHERE code='$code';

} else {
echo "Error updating record: " . mysqli_error($conn);
}

谁能告诉我如何用 php mysqli 程序方式编写这个。

最佳答案

您忘记调用mysqli_query()来执行UPDATE

if (mysqli_query($conn, $sql1)) {
$sql2="UPDATE activations SET status='in use' WHERE code='$code'";
if (!mysqli_query($conn, $sql2)) {
echo "Error updating activations: " . mysqli_error($conn);
}
} else {
echo "Error inserting student: " . mysqli_error($conn);
}

关于php - 在php中插入另一个表后如何更新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38407149/

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