一些代码从选择数据开始,然后检查要插入的行号是否为 0,然后继续正常过程。问题是正常过程取决于select
不存在的语句,因为它存储在insert
. 如何在没有 ajax 或与 html 相关的任何内容的情况下刷新 PHP 内部的数据请求?下面是一个例子来解释:
$user = $_GET['user']; // not stored user
$select = mysql_query("SELECT * FROM `table` WHERE username = ".$user);
$row = mysql_fetch_array($select);
$rownum = mysql_num_rows($select);
if(!$rownum){
mysql_query("INSERT INTO table (username, something) VALUES ('$user', 1)");
}
/* Here comes the problem */
if($row['something'] == 0){
die("Not found !"); // THIS if returns true since it was not found at first place before inserting
// i want it to refresh the $select data so it could be read as 1
}
到目前为止,我如何解决它是通过重复使用语句下方的$select
and代码$row
insert
if(!$rownum){
mysql_query("INSERT INTO table (username, something) VALUES ('$user', 1)");
}
$select = mysql_query("SELECT * FROM `table` WHERE username = ".$user);
$row = mysql_fetch_array($select);
[..]
我想要一个更简单的方法来做到这一点