我试图检查数据库中是否已存在字符串。
更新:
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Start SQL check
$steamid = $_POST["steamid"];
$sql = "SELECT steamid FROM blacklist WHERE steamid = $steamid";
if ($result=mysqli_query($con,$sql))
{
// Return the number of rows in result set
$rowcount=mysqli_num_rows($result);
}
if($rowcount >=1)
{
echo "not added as we already have steam id in databse";
}
else
{
echo "code to add it here";
//SteamID not in database
//Add it to databse
$sql = "INSERT INTO blacklist (steamid, permBanned)
VALUES ('$steamid', false)";
mysqli_query($con,$sql);
echo "Added to blacklist";
}
mysqli_close($con);
插入确实有效,但选择并检查它是否存在并不存在。我不知道为什么?
感谢您的帮助。
(表结构:blacklistID:autonumber,steamid:string,permBanned:bool)
所以我更新了它以尝试使用MySQLi,但我似乎没有随处可见..任何人都可以帮助吗?我真的很感激。
答案 0 :(得分:-2)
尝试
$sql = mysql_query("SELECT steamid FROM blacklist WHERE steamid =". $steamid);
if(mysql_num_rows($sql)>0)
{
echo "not added as we already have that ID in the database";
}