only one Posted February 8, 2007 Share Posted February 8, 2007 heres my code $checkuser = mysql_query("SELECT username FROM clanapps WHERE username = '$username'"); $username_exist = mysql_num_rows($checkuser); heres the error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/d-pures.freehostia.com/pages/Apply.php on line 9 Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/ Share on other sites More sharing options...
papaface Posted February 8, 2007 Share Posted February 8, 2007 How are you connecting to mysql and how are you selecting the db? Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180073 Share on other sites More sharing options...
only one Posted February 8, 2007 Author Share Posted February 8, 2007 <?php if (isset($_POST["clan"])) { $username = $_POST["user"]; if($clan==NULL) { echo "A field was left blank."; }else{ $checkuser = mysql_query("SELECT username FROM clanapps WHERE username='$username'"); $username_exist = mysql_num_rows($checkuser); if ($username_exist>0) { echo "You have already applied"; }else{ $query = "INSERT INTO clanapps (`username`, `clan`) VALUES('$username','$clan)"; mysql_query($query) or die(mysql_error()); echo "you succefully applied for $clan"; }}} ?> Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180074 Share on other sites More sharing options...
only one Posted February 8, 2007 Author Share Posted February 8, 2007 it connects further up the page Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180075 Share on other sites More sharing options...
papaface Posted February 8, 2007 Share Posted February 8, 2007 hmm. Try: <?php if (isset($_POST["clan"])) { $username = $_POST['user']; if($clan==NULL) { echo "A field was left blank."; }else{ $checkuser = mysql_query("SELECT `username` FROM `clanapps` WHERE `username`='".$username."'"); $username_exist = mysql_num_rows($checkuser); if ($username_exist>0) { echo "You have already applied"; }else{ $query = "INSERT INTO clanapps (`username`, `clan`) VALUES('$username','$clan)"; mysql_query($query) or die(mysql_error()); echo "you succefully applied for $clan"; }}} ?> Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180079 Share on other sites More sharing options...
jcbarr Posted February 8, 2007 Share Posted February 8, 2007 First make sure that you are actually connected to the database, then you might want to make sure that your table and column names match what is actually in the database. Start there and you will soon find the problem I am guessing. Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180080 Share on other sites More sharing options...
jcbarr Posted February 8, 2007 Share Posted February 8, 2007 You are missing a ' in this line; $query = "INSERT INTO clanapps (`username`, `clan`) VALUES('$username','$clan)"; It should look like this; $query = "INSERT INTO clanapps (`username`, `clan`) VALUES('$username','$clan')"; It might not be actually inserting the info because of the error in that syntax. Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180081 Share on other sites More sharing options...
only one Posted February 8, 2007 Author Share Posted February 8, 2007 its obviously connecting to the database if all the other coides are working, everytime i use the mysql_num_rows() function i always get an error, it seems to work alright on my register page Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180082 Share on other sites More sharing options...
only one Posted February 8, 2007 Author Share Posted February 8, 2007 no different Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180084 Share on other sites More sharing options...
jcbarr Posted February 8, 2007 Share Posted February 8, 2007 What does your table structure look like for the clanapps table? Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180086 Share on other sites More sharing options...
only one Posted February 8, 2007 Author Share Posted February 8, 2007 CREATE TABLE `clanapps` ( `id` int(11) NOT NULL auto_increment, `clan` varchar(25) NOT NULL default '', `username` varchar(25) NOT NULL default '', PRIMARY KEY (`id`) Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180090 Share on other sites More sharing options...
only one Posted February 8, 2007 Author Share Posted February 8, 2007 oops just realised, i didnt coppy the full error, if it makes much difference Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/d-pures.freehostia.com/pages/Apply.php on line 9 Unknown column 'username' in 'field list' Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180093 Share on other sites More sharing options...
only one Posted February 8, 2007 Author Share Posted February 8, 2007 anyone figure it yet? ??? Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180127 Share on other sites More sharing options...
13th_Star Posted February 8, 2007 Share Posted February 8, 2007 try this instead: $checkuser = mysql_query("SELECT * FROM `clanapps` WHERE `username` = '$username'"); $username_exist = mysql_num_rows($checkuser); Link to comment https://forums.phpfreaks.com/topic/37640-mysql-num-rows/#findComment-180181 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.