Jump to content

MySQL WHERE


martinc126

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

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.