Jump to content

Recommended Posts

Hello,

 

Can you please help me. I've wrote this but for some reason it wont work.

 

If i only use one WHERE it works but i need it to check two fields in the row.

 

if(mysql_num_rows(mysql_query("SELECT * FROM data WHERE `surname` = '$dc_sur' and `dob` = '$dc_dob'")))
{
// Code inside if block if surname and date of birth is already there
include "duplicate.php";
exit();
} 

 

Any help would be much appericated

 

Regards

 

Martin

Link to comment
https://forums.phpfreaks.com/topic/244658-mysql-where/
Share on other sites

That is valid syntax, if it doesn't work, it is because of the contents of a variable, or a table.  Do NOT combine query functions, as you have no control of de-bugging when you do.

 

$sql = "SELECT * FROM data WHERE `surname` = '$dc_sur' and `dob` = '$dc_dob'";
$result = mysql_query($sql) or trigger_error($sql . ' has an error.<br />' . mysql_error());
if(mysql_num_rows() > 0)
{
// Code inside if block if surname and date of birth is already there
include "duplicate.php";
exit();
} 

 

Are you sure that the data exists in the table?

Link to comment
https://forums.phpfreaks.com/topic/244658-mysql-where/#findComment-1256686
Share on other sites

Hi,

 

I've tried the above but still doesn't work, I've even entered the actual data ie `surename` = 'MySurname' AND `dob` = '26-11-1986' but it still fails.

 

There is already a row in the table data which contains them two fields but doesn't do anything.

 

I were wanting it to display the include if it found to contain the user given data already in the database.

 

This is the error i got

 

 

Warning: mysql_num_rows() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\ars\client-side\enroll-auth.php on line 27

 

Kind Regards

 

Martin

Link to comment
https://forums.phpfreaks.com/topic/244658-mysql-where/#findComment-1256747
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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