gpt4 book ai didi

PHP写入MYSQL变量等于0

转载 作者:行者123 更新时间:2023-11-29 14:59:42 25 4
gpt4 key购买 nike

如果变量等于 0,我尝试写入数据库。问题是,即使变量等于 1,它仍然写入数据库。出了什么问题??

echo $new_user;

if ($new_user == 0) {

//SENT NEW USER WELCOME MESSAGE

$adminid = '9';
$welcomemessagetitle = 'Welcome to The site';
$welcomemessagecontent = 'Hello and welcome';

$addmessages = "INSERT into `user_messages`(`to_user`,`from_user`,`title`,`content`)
VALUES ('$userid','$adminid','$welcomemessagetitle','$welcomemessagecontent');";

$query = mysql_query($addmessages) or die(mysql_error());

//SET USER AS NOT NEW USER

$newuservalue = '1';

$notnewuser = "UPDATE users SET new_user = $newuservalue WHERE id = $userid" ;

$query2 = mysql_query($notnewuser) or die(mysql_error());

} elseif ($new_user == 1) {};

更新完整代码::

<?php 
session_start();
include "../includes/db_connect.php";
///profile/index.php
if($_SESSION['id'])
{
$username = $_SESSION['username'];
$userid = $_SESSION['id'];
//WRITE FIRST TIME LOGIN INFORMATION TO DATABASE
$sql="SELECT new_user from `users` WHERE `id`= $userid ";
$res=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_assoc($res)) $new_user = $row['new_user'] ;
echo $new_user;
if ($new_user == 0) {
//SENT NEW USER WELCOME MESSAGE
$adminid = '9';
$welcomemessagetitle = 'Welcome to Escorvee';
$welcomemessagecontent = 'Hello and welcome';
$addmessages = "INSERT into `user_messages`(`to_user`,`from_user`,`title`,`content`)
VALUES ('$userid','$adminid','$welcomemessagetitle','$welcomemessagecontent');";

$query = mysql_query($addmessages) or die(mysql_error());
//SET USER AS NOT NEW USER
$newuservalue = '1';
$notnewuser = "UPDATE users SET new_user = $newuservalue WHERE id = $userid" ;
$query2 = mysql_query($notnewuser) or die(mysql_error());
} elseif ($new_user == 1) {};
}
?>

最佳答案

如果变量 $new_user 的值为 1,那么您的代码将不会被执行,因此我猜测以下情况之一适用:

  • $new_user 不是 1。
  • 正在从其他位置修改数据库。
  • 您的脚本被调用两次。

要找出答案,您必须在问题中提供更多信息。

关于PHP写入MYSQL变量等于0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3565219/

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