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 Quote Link to comment 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? Quote Link to comment 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"; }}} ?> Quote Link to comment 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 Quote Link to comment 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"; }}} ?> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
only one Posted February 8, 2007 Author Share Posted February 8, 2007 no different Quote Link to comment 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? Quote Link to comment 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`) Quote Link to comment 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' Quote Link to comment Share on other sites More sharing options...
only one Posted February 8, 2007 Author Share Posted February 8, 2007 anyone figure it yet? ??? Quote Link to comment 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); Quote Link to comment 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.