Jump to content

MYSQL NUM ROW CHECK NOT WORKING


Orionsbelter

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.