Jump to content

MYSQL NUM ROW CHECK NOT WORKING


Orionsbelter
 Share

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
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

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.