I'm trying to check if a string is already present in my database.
UPDATED:
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);
The insert does work but the select and checking to see if it exists doesn't. I don't know why?
Thanks for any help.
(Table structure: blacklistID : autonumber, steamid : string, permBanned : bool)
So I updated it to try and use MySQLi but I don't seem to be getting anywhere with this.. Can anyone now help? I really appreciate it.