desjardins2010 Posted January 13, 2011 Share Posted January 13, 2011 code <?php //storecodefound.php v1.0 //purpose is to store the http refer and the code associated with the site to a db to be collected and verified by submitcode.php $code = $_GET['code']; $site = $_SERVER['HTTP_HOST']; //check to see if the code already present $connect = mysql_connect("localhost","root","") or die (mysql_error()); $check = mysql_query("SELECT code FROM hunter.codes WHERE code='$code'") or die (mysql_error()); $row = mysql_num_rows($check); echo "result of \$row is ".$row; echo "<br />"; if ($row = 0) { //insert into db cause it's not there mysql_query("INSERT INTO hunter.codes (id, code, site) VALUES ('','$code','$site')") or die (mysql_error()); } else { //echo it's already here echo "Code already found on server!"; } ?> my question is the result of $row is infact 0 and the if statement says if $row is 0 to insert into db and instead it's given me the code is already found? Link to comment https://forums.phpfreaks.com/topic/224337-quick-question/ Share on other sites More sharing options...
Maq Posted January 13, 2011 Share Posted January 13, 2011 I would think that the INSERT would be executed every time since you are assigning $row to 1: if ($row = 0) { which is always true. I think you want: if ($row === 0) { Link to comment https://forums.phpfreaks.com/topic/224337-quick-question/#findComment-1158999 Share on other sites More sharing options...
desjardins2010 Posted January 13, 2011 Author Share Posted January 13, 2011 shoot thanks man Link to comment https://forums.phpfreaks.com/topic/224337-quick-question/#findComment-1159002 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.