martinc126 Posted August 13, 2011 Share Posted August 13, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/244658-mysql-where/ Share on other sites More sharing options...
jcbones Posted August 13, 2011 Share Posted August 13, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/244658-mysql-where/#findComment-1256686 Share on other sites More sharing options...
martinc126 Posted August 13, 2011 Author Share Posted August 13, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/244658-mysql-where/#findComment-1256747 Share on other sites More sharing options...
jcbones Posted August 13, 2011 Share Posted August 13, 2011 I was being stupid, and didn't put the argument in the function. if(mysql_num_rows($result) > 0) { Quote Link to comment https://forums.phpfreaks.com/topic/244658-mysql-where/#findComment-1256772 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.