JP128 Posted June 24, 2006 Share Posted June 24, 2006 PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource...<?phpinclude "config.php";checkConfirm(); //Confirms passwords match.checkEmpty(); //Checks for empty forms.dbConnect(); //Connects to DB$username = $_POST['username'];$email = $_POST['email'];$sql = "select * from registry where user='$username'";$result = mysql_query($sql);$num_rows = mysql_num_rows($result);[b] // <=-=-=-=- This is where I get the error...[/b]if ($num_rows = 0) {mysql_query("insert into registry values ('$firstname', '$lastname', '$username', MD5('$password'), '$email'");} //end of if Quote Link to comment Share on other sites More sharing options...
hackerkts Posted June 24, 2006 Share Posted June 24, 2006 [code]$sql = "select * from registry where user='$username'";[/code]You need to specify which column.[code]$sql = "select firstname from registry where user='$username'";[/code] Quote Link to comment Share on other sites More sharing options...
JP128 Posted June 24, 2006 Author Share Posted June 24, 2006 I did that, and now it always returns false Quote Link to comment Share on other sites More sharing options...
jfee1212 Posted June 24, 2006 Share Posted June 24, 2006 Make sure that the table you're selecting columns from is truley registry.if it was Registry or REGISTRY it would return false Quote Link to comment Share on other sites More sharing options...
JP128 Posted June 24, 2006 Author Share Posted June 24, 2006 It is. I have the table correct. Quote Link to comment Share on other sites More sharing options...
.josh Posted June 24, 2006 Share Posted June 24, 2006 [!--quoteo(post=387356:date=Jun 23 2006, 09:49 PM:name=hackerkts)--][div class=\'quotetop\']QUOTE(hackerkts @ Jun 23 2006, 09:49 PM) [snapback]387356[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]$sql = "select * from registry where user='$username'";[/code]You need to specify which column.[code]$sql = "select firstname from registry where user='$username'";[/code][/quote]no you don't. * selects all columns. firstname just selects firstname. why don't you add this red part here:$result = mysql_query($sql)[!--coloro:red--][span style=\"color:red\"][!--/coloro--] or die(mysql_error());[!--colorc--][/span][!--/colorc--]i bet it might give you some useful hints as to what's wrong. Quote Link to comment Share on other sites More sharing options...
JP128 Posted June 24, 2006 Author Share Posted June 24, 2006 Yea, but there isnt an error. it just always returns false Quote Link to comment Share on other sites More sharing options...
.josh Posted June 24, 2006 Share Posted June 24, 2006 so you get no error from that? okay, then add this:$sql = "select * from registry where user='$username'";[!--coloro:red--][span style=\"color:red\"][!--/coloro--]echo $sql;[!--colorc--][/span][!--/colorc--]this will echo the actual query string being sent to the db. maybe $username is empty, or not the value you expect. Quote Link to comment Share on other sites More sharing options...
JP128 Posted June 24, 2006 Author Share Posted June 24, 2006 I will probably recreate the script. But I will try that tomorrow, I need to get to sleep. lol. Thanks, see ya. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 24, 2006 Share Posted June 24, 2006 Going back to your original post, you said:[code]<?php$sql = "select * from registry where user='$username'";$result = mysql_query($sql);$num_rows = mysql_num_rows($result); // <=-=-=-=- This is where I get the error...?>[/code]That mean that the mysql_query did not return a meaningful result. Change the query line to be:[code]<? $result = mysql_query($sql) or die('Problem with the query: ' . $sql . '<br>' . mysql_error()); ?>[/code]You script will then stop if there is an error and display both the error message and your query.Ken Quote Link to comment Share on other sites More sharing options...
JP128 Posted June 24, 2006 Author Share Posted June 24, 2006 I re-created the entire script. I dont get an error. I know my script is running, and will tell the errors, because I changed the table name, and it says it doesnt exist. So then I turned it back. I connect to the DB, and select the tables. But it wont do anything more than that. Quote Link to comment Share on other sites More sharing options...
.josh Posted June 24, 2006 Share Posted June 24, 2006 did you echo $sql ?does it show something like [b]select * from registry where user='blah'[/b]on your screen, or does it show[b]select * from registry where user=''[/b]and if it shows the first, copy and paste it into phpmyadmin and see if you get a result. Quote Link to comment Share on other sites More sharing options...
JP128 Posted June 24, 2006 Author Share Posted June 24, 2006 It doesnt echo anything. Quote Link to comment Share on other sites More sharing options...
AndyB Posted June 24, 2006 Share Posted June 24, 2006 Do you mean that echo $sql produces absolutely nothing whatsoever????? Quote Link to comment Share on other sites More sharing options...
JP128 Posted June 25, 2006 Author Share Posted June 25, 2006 correctDoes anyone have like a messenger that I can talk to them directly? It would be much faster. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 25, 2006 Share Posted June 25, 2006 Can you post you're new script?Ken Quote Link to comment Share on other sites More sharing options...
.josh Posted June 25, 2006 Share Posted June 25, 2006 you must be doing something wrong, as in, not following our instructions. you say that you know it connects to the db fine, cuz you change the parameters to some random thing and you get error messages. so obviously your script is being run. therefore i see no reason why doing $sql = 'select * ...';echo $sql; does not echo out anything. that does not make sense, unless you just aren't doing it, or somehow doing like echo $someothervarname; or something. Quote Link to comment Share on other sites More sharing options...
JP128 Posted June 25, 2006 Author Share Posted June 25, 2006 This is in CONFIG.PHP<?phpfunction dbConnect() { //Start of dbConnectmysql_connect("localhost", "jp128", "****");mysql_select_db("jp128");} //End of dbConnectfunction registerCheck(){$firstname = $_REQUEST['firstname'];$lastname = $_REQUEST['lastname'];$username = $_REQUEST['username'];$password = $_REQUEST['password'];$email = $_REQUEST['email'];dbConnect();$output = mysql_query("SELECT * FROM registry WHERE username=$username OR email=$email");$output_rows = mysql_num_rows($output);if($output_rows = 0){mysql_query("INSERT INTO registry VALUES('$firstname','$lastname','$username','$password','$email'");} elseif ($output_rows > 1){echo "MYSQL ERROR. IS MORE THAN ONE OF THESE USERNAMES. PLEASE CONTACT webmaster@jp128.mooo.com!";} elseif ($output_rows = 1){echo"I am sorry, but that username or email address already exists in the database. If this is an error, please contact webmaster@jp128.mooo.com.";}}?>This is REGISTERCHECK.php<?phpinclude "config.php";registerCheck();?> Quote Link to comment Share on other sites More sharing options...
.josh Posted June 25, 2006 Share Posted June 25, 2006 omg where to begin...[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]This is in CONFIG.PHP<?phpfunction dbConnect() { //Start of dbConnectmysql_connect("localhost", "jp128", "****");mysql_select_db("jp128");} //End of dbConnectfunction registerCheck(){$firstname = $_REQUEST['firstname'];$lastname = $_REQUEST['lastname'];$username = $_REQUEST['username'];$password = $_REQUEST['password'];$email = $_REQUEST['email'];dbConnect();$output = mysql_query("SELECT * FROM registry WHERE username=[!--coloro:red--][span style=\"color:red\"][!--/coloro--]'[!--colorc--][/span][!--/colorc--]$username[!--coloro:red--][span style=\"color:red\"][!--/coloro--]'[!--colorc--][/span][!--/colorc--] OR email=[!--coloro:red--][span style=\"color:red\"][!--/coloro--]'[!--colorc--][/span][!--/colorc--]$email[!--coloro:red--][span style=\"color:red\"][!--/coloro--]'[!--colorc--][/span][!--/colorc--]");$output_rows = mysql_num_rows($output);if($output_rows =[!--coloro:red--][span style=\"color:red\"][!--/coloro--]=[!--colorc--][/span][!--/colorc--] 0){//assuming these are the right column namesmysql_query("INSERT INTO registry [!--coloro:red--][span style=\"color:red\"][!--/coloro--](firstname, lastname, username, password, email) [!--colorc--][/span][!--/colorc--]VALUES('$firstname','$lastname','$username','$password','$email'");[!--coloro:red--][span style=\"color:red\"][!--/coloro--]//strictly speaking, you shouldn't be scripting this elseif > 1// in the first place. you should have it setup like, // if (blah > 0) { 'name already taken' } else { insert info } [!--colorc--][/span][!--/colorc--]} elseif ($output_rows > 1){echo "MYSQL ERROR. IS MORE THAN ONE OF THESE USERNAMES. PLEASE CONTACT webmaster@jp128.mooo.com!";[!--coloro:red--][span style=\"color:red\"][!--/coloro--]should be an else, not an elseif[!--colorc--][/span][!--/colorc--]} [!--coloro:red--][span style=\"color:red\"][!--/coloro--]else[!--colorc--][/span][!--/colorc--] ($output_rows =[!--coloro:red--][span style=\"color:red\"][!--/coloro--]=[!--colorc--][/span][!--/colorc--] 1){echo"I am sorry, but that username or email address already exists in the database. If this is an error, please contact webmaster@jp128.mooo.com.";}}?>This is REGISTERCHECK.php<?phpinclude "config.php";registerCheck();?>[/quote] 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.