Piranha wrote:A few notes on this. First you should only do this check if the column(s) used is unique together. Otherwise you might get results that is not really a duplicate. Second you should use SELECT COUNT(*) when you just want to see if something exists or only want to count something. Otherwise everything is returned from the database and then just discarded, it takes lots of time. Third you should be sure to use the right function to avoid database injection. For mysql it is [man]mysql_real_escape_string[/man]. The query should then look something like this:
$sql = "SELECT COUNT(*) FROM table WHERE column = " . mysql_real_escape_string($_POST['data']);
Hi, this is my code:
$fname=$_POST['fname'];
$laname=$_POST['lname'];
$storenumber=$_POST['storenumber'];
$type=$_POST['type'];
$check = mysql_query("SELECT COUNT(*) FROM benugo_staff WHERE fname = " . mysql_real_escape_string($_POST['fname']) . " AND lname = " . mysql_real_escape_string($_POST['lname']));
$number = '0';
if ($check > $number) {
echo ("something is wrong");
}else{
mysql_query("INSERT INTO `staff` VALUES ('', '$fname', '', '$lname', '', '$storenumber', '$type', '', 'Active')") or die(mysql_error());
echo "<meta http-equiv=\"refresh\" content=\"5;URL=useradd.php?cid=".$cid."\" />
<span class=\"column_header\">Your information has been successfully added to the database</span><br />
<span class=\"column_header2\">you will shortly be redirected to the course attendance form to add your team member to the course.</span><br />
</p>";}
There is no php error, and it posts to the database
The result from the query is 6, but it is still posting the entry into the database?