oops73 Posted May 15, 2007 Share Posted May 15, 2007 Hi all! Can anyone take a look at this code and explain to me why i get this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in i:\easyphp1-8\www\project.php on line 36 I have tried and tried... nothing works. Please take a look. Thanks! // Check If UNIQUE // $db = mysql_connect($host, $login, $password) or die ('Erreur connection'); mysql_select_db($base, $db) or die ('Erreur select database'); $result = mysql_query("SELECT * FROM users WHERE unique_id='$unique_id'"); $num_rows = mysql_num_rows($result); // LINE 36 <--- $num_rows > 0 ? $unique = FALSE : $unique = TRUE; mysql_close(); if (FALSE == $unique){ $error['unique_id'] = "Already send to the database!"; } else if (TRUE == $unique) { Quote Link to comment https://forums.phpfreaks.com/topic/51566-what-seams-to-be-wrong-here/ Share on other sites More sharing options...
Psycho Posted May 15, 2007 Share Posted May 15, 2007 Most likely there is an error in your query. Change the following line: $result = mysql_query("SELECT * FROM users WHERE unique_id='$unique_id'") or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/51566-what-seams-to-be-wrong-here/#findComment-253942 Share on other sites More sharing options...
oops73 Posted May 15, 2007 Author Share Posted May 15, 2007 Thanks for the replay. the change helped a bit, but i got this instead : Unknown column 'unique_id' in 'where clause' any idea? Quote Link to comment https://forums.phpfreaks.com/topic/51566-what-seams-to-be-wrong-here/#findComment-253947 Share on other sites More sharing options...
marf Posted May 15, 2007 Share Posted May 15, 2007 before this line throw in an echo like so echo "ID: ".$unique_id; $result = mysql_query("SELECT * FROM users WHERE unique_id='$unique_id'") or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/51566-what-seams-to-be-wrong-here/#findComment-253951 Share on other sites More sharing options...
kenrbnsn Posted May 15, 2007 Share Posted May 15, 2007 The error is telling you exactly what is wrong. There is no column or field named "unique_id" in the table named "users". Ken Quote Link to comment https://forums.phpfreaks.com/topic/51566-what-seams-to-be-wrong-here/#findComment-253952 Share on other sites More sharing options...
oops73 Posted May 15, 2007 Author Share Posted May 15, 2007 ok, Here is an overview of the code so it´s easier to help me. // variables // $listVar = array('IDcode', 'unique_id', 'Fname', 'Lname', 'Region', 'Depart', 'Email'); $noEmptyCheck = array('unique_id'); // Collect variables FORM // foreach ($listVar as $value) { if ($value !== 'IDcode' || $value !== 'unique_id') { isset($_SESSION[$value]) ? $$value = htmlentities(trim($_SESSION[$value]), ENT_QUOTES) : $$value = NULL; } } isset($_POST['IDcode']) ? $IDcode = $_POST['IDcode'] : $IDcode = NULL; ////////// WORK now ///////// if (isset($_POST['action']) && ('add' == $_POST['action'])) { ////////// ACTION ///////// // Collect variables ACTION // foreach ($listVar as $value) { isset($_POST[$value]) ? $$value = htmlentities(trim($_POST[$value]), ENT_QUOTES) : $$value = NULL; } // Check If UNIQUE // $db = mysql_connect($host, $login, $password) or die ('Erreur connection'); mysql_select_db($base, $db) or die ('Erreur select database'); echo "ID: ".$unique_id; $result = mysql_query("SELECT * FROM users WHERE unique_id='$unique_id'"); $num_rows = mysql_num_rows($result); $num_rows > 0 ? $unique = FALSE : $unique = TRUE; mysql_close(); if (FALSE == $unique){ $error['unique_id'] = "Already send to the database!"; } else if (TRUE == $unique) { Quote Link to comment https://forums.phpfreaks.com/topic/51566-what-seams-to-be-wrong-here/#findComment-253968 Share on other sites More sharing options...
oops73 Posted May 15, 2007 Author Share Posted May 15, 2007 The error is telling you exactly what is wrong. There is no column or field named "unique_id" in the table named "users". Ken Hi Ken, please take a look at the code agian. I have set "IDcode" as "unique_id" in the database. If i add a "unique_id" field in the table i got my premade errormessage saying that there is an error adding to database. any ideas? /Joel Quote Link to comment https://forums.phpfreaks.com/topic/51566-what-seams-to-be-wrong-here/#findComment-254012 Share on other sites More sharing options...
Psycho Posted May 15, 2007 Share Posted May 15, 2007 Hi Ken, please take a look at the code agian. I have set "IDcode" as "unique_id" in the database. If i add a "unique_id" field in the table i got my premade errormessage saying that there is an error adding to database. any ideas? So, then shouldn't you be using: $result = mysql_query("SELECT * FROM users WHERE IDcode='$unique_id'"); Quote Link to comment https://forums.phpfreaks.com/topic/51566-what-seams-to-be-wrong-here/#findComment-254040 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.