Orionsbelter Posted December 8, 2013 Share Posted December 8, 2013 Hi there, Am submitting an excel spread sheet via an upload php script I check in the do loop to see if the info already exists in my selected database using the info below $check_for_duped_person=mysql_num_rows(mysql_query("SELECT `id` FROM `delivery_information` WHERE `contact_name`='$recipient_name' AND `post_code`='$ship_postal_code'")); if($check_for_duped_person="1"){echo"error $check_for_duped_person $recipent_name";}else{ It always seems to return 1 when even when the table delivery_information is empty. I need to make sure that the duplicated rows in the CSV file aren't submitted twice. This can only be done by the upload script and the above coding. I can not do it via excel as it will be user submitted any help will be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/284623-mysql-num-row-check-not-working/ Share on other sites More sharing options...
hitman6003 Posted December 8, 2013 Share Posted December 8, 2013 Print out your query and make sure it is what you expect it to be: print '<pre>My query is:'; print " SELECT `id` FROM `delivery_information` WHERE `contact_name` = '$recipient_name' AND `post_code` = '$ship_postal_code'"; Link to comment https://forums.phpfreaks.com/topic/284623-mysql-num-row-check-not-working/#findComment-1461654 Share on other sites More sharing options...
Orionsbelter Posted December 8, 2013 Author Share Posted December 8, 2013 I tried this it seems that its searching the correct information but it doesn't exist in the table. But it's returning a value of 1. Could it be because it's in a loop? Link to comment https://forums.phpfreaks.com/topic/284623-mysql-num-row-check-not-working/#findComment-1461655 Share on other sites More sharing options...
hitman6003 Posted December 8, 2013 Share Posted December 8, 2013 You only have one "=".... if($check_for_duped_person = "1")You need two "==" for comparison. The single "=" sets the value to 1. Link to comment https://forums.phpfreaks.com/topic/284623-mysql-num-row-check-not-working/#findComment-1461656 Share on other sites More sharing options...
mac_gyver Posted December 8, 2013 Share Posted December 8, 2013 a) one equal = is an assignment operator. two == is a comparison operator. this is a first-week beginner mistake. you have 400+ posts over years of being a member on this forum. why are you making such a mistake at this point in time? b) you should almost never run queries inside of loops. for inserting/updating a large amount of data, you should be using one of the following methods - 1 - a multi-value INSERT .... ON DUPLICATE KEY UPDATE query 2 - a multi-value INSERT IGNORE query 3 - a multi-value REPLACE Link to comment https://forums.phpfreaks.com/topic/284623-mysql-num-row-check-not-working/#findComment-1461658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.