DarkPrince2005 Posted May 7, 2008 Share Posted May 7, 2008 I am trying to have a database searched for an entry that matches an email address typed in a textbox, and if no entries matching the entered email is found to then add it to the database <?php mysql_connect("localhost","root",""); mysql_select_db("test"); $q=mysql_query("select * from emails where Email like '$_POST[email]';"); $num=mysql_num_rows($q); if ($num=0) { mysql_query ("INSERT INTO emails values('','$_POST[email]')"); echo "<script language=JavaScript>window.location='add.php'</script>"; } else { echo "Entry already exists"; } mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/104626-solved-if-statement-and-mysql-queries/ Share on other sites More sharing options...
LemonInflux Posted May 7, 2008 Share Posted May 7, 2008 <?php mysql_connect("localhost","root",""); mysql_select_db("test"); $query = mysql_query("select * from emails where Email like '$_POST[email]';"); $num = mysql_num_rows($q); # Here's the bit. = should be == (see below).. if ($num == 0) { mysql_query ("INSERT INTO emails values('','$_POST[email]')"); echo "<script language=JavaScript>window.location='add.php'</script>"; } else { echo "Entry already exists"; } mysql_close(); ?> changed = to ==. = sets a value, == checks a value. Link to comment https://forums.phpfreaks.com/topic/104626-solved-if-statement-and-mysql-queries/#findComment-535489 Share on other sites More sharing options...
DarkPrince2005 Posted May 7, 2008 Author Share Posted May 7, 2008 Thanx allot, I really apreciate it Link to comment https://forums.phpfreaks.com/topic/104626-solved-if-statement-and-mysql-queries/#findComment-535493 Share on other sites More sharing options...
LemonInflux Posted May 7, 2008 Share Posted May 7, 2008 No problem. Just remember to click 'Topic Solved' Link to comment https://forums.phpfreaks.com/topic/104626-solved-if-statement-and-mysql-queries/#findComment-535499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.