Originally posted by tsinka
Hi,
let's say you want to check if a given user already exists then do something like:
<?PHP
$user = $_POST['username'];
$res = mysql_query("SELECT COUNT(*) AS cnt FROM thetable WHERE user='"
.mysql_escape_string($user)
."'");
$row = mysql_fetch_array($res);
$cnt = $row['cnt'];
if ($cnt>0) {
// user already exists
} else {
// user doesn't exist
}
?>
Thomas [/B]
I did this
$url = $_POST['company_url'];
$res = mysql_query("SELECT COUNT(*) AS cnt FROM hosts WHERE company_url='"
.mysql_escape_string($url)
."'");
$row = mysql_fetch_array($res);
$cnt = $row['cnt'];
if ($cnt>0)
{
print 'Host already exists.';
exit;
}
else
{
mysql_query($query,$conn) or die("SQL error: ".mysql_error());
mysql_close($conn);
header("Location: tu.php");
exit;
}
But it doesn't work. It fails the test whether the url is already in the db or not, and adds it anyway...
Any ideas?
Thanks