Jump to content

Archived

This topic is now archived and is closed to further replies.

JP128

MySQL with PHP...

Recommended Posts

PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource...


<?php
include "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

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
I did that, and now it always returns false

Share this post


Link to post
Share on other sites
Make sure that the table you're selecting columns from is truley registry.

if it was Registry or REGISTRY it would return false

Share this post


Link to post
Share on other sites
It is. I have the table correct.

Share this post


Link to post
Share on other sites
[!--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.

Share this post


Link to post
Share on other sites
Yea, but there isnt an error. it just always returns false

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I will probably recreate the script. But I will try that tomorrow, I need to get to sleep. lol. Thanks, see ya.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Do you mean that echo $sql produces absolutely nothing whatsoever?????

Share this post


Link to post
Share on other sites
correct


Does anyone have like a messenger that I can talk to them directly? It would be much faster.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
This is in CONFIG.PHP

<?php
function dbConnect() { //Start of dbConnect
mysql_connect("localhost", "jp128", "****");
mysql_select_db("jp128");
} //End of dbConnect

function 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

<?php
include "config.php";
registerCheck();
?>

Share this post


Link to post
Share on other sites
omg where to begin...
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
This is in CONFIG.PHP

<?php
function dbConnect() { //Start of dbConnect
mysql_connect("localhost", "jp128", "****");
mysql_select_db("jp128");
} //End of dbConnect

function 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 names
mysql_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

<?php
include "config.php";
registerCheck();
?>
[/quote]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.