Jump to content


Photo

MySQL with PHP...


  • Please log in to reply
18 replies to this topic

#1 JP128

JP128
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationWisconsin

Posted 24 June 2006 - 02:35 AM

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); // <=-=-=-=- This is where I get the error...

if ($num_rows = 0) {

mysql_query("insert into registry values ('$firstname', '$lastname', '$username', MD5('$password'), '$email'");

} //end of if
-----------------------------------------------------------------------
John Ensign - Age 16 - PHP Learner

My email is Johnny.Ensign@gmail.com

#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 24 June 2006 - 02:49 AM

$sql = "select * from registry where user='$username'";

You need to specify which column.
$sql = "select firstname from registry where user='$username'";


Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#3 JP128

JP128
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationWisconsin

Posted 24 June 2006 - 02:54 AM

I did that, and now it always returns false
-----------------------------------------------------------------------
John Ensign - Age 16 - PHP Learner

My email is Johnny.Ensign@gmail.com

#4 jfee1212

jfee1212
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 24 June 2006 - 04:03 AM

Make sure that the table you're selecting columns from is truley registry.

if it was Registry or REGISTRY it would return false

#5 JP128

JP128
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationWisconsin

Posted 24 June 2006 - 05:20 AM

It is. I have the table correct.
-----------------------------------------------------------------------
John Ensign - Age 16 - PHP Learner

My email is Johnny.Ensign@gmail.com

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 24 June 2006 - 06:29 AM

[!--quoteo(post=387356:date=Jun 23 2006, 09:49 PM:name=hackerkts)--][div class=\'quotetop\']QUOTE(hackerkts @ Jun 23 2006, 09:49 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$sql = "select * from registry where user='$username'";

You need to specify which column.
$sql = "select firstname from registry where user='$username'";
[/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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 JP128

JP128
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationWisconsin

Posted 24 June 2006 - 06:30 AM

Yea, but there isnt an error. it just always returns false
-----------------------------------------------------------------------
John Ensign - Age 16 - PHP Learner

My email is Johnny.Ensign@gmail.com

#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 24 June 2006 - 06:38 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#9 JP128

JP128
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationWisconsin

Posted 24 June 2006 - 06:49 AM

I will probably recreate the script. But I will try that tomorrow, I need to get to sleep. lol. Thanks, see ya.
-----------------------------------------------------------------------
John Ensign - Age 16 - PHP Learner

My email is Johnny.Ensign@gmail.com

#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 24 June 2006 - 03:46 PM

Going back to your original post, you said:
<?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...
?>
That mean that the mysql_query did not return a meaningful result. Change the query line to be:
<? $result = mysql_query($sql) or die('Problem with the query: ' . $sql . '<br>' . mysql_error()); ?>
You script will then stop if there is an error and display both the error message and your query.

Ken

#11 JP128

JP128
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationWisconsin

Posted 24 June 2006 - 05:31 PM

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.
-----------------------------------------------------------------------
John Ensign - Age 16 - PHP Learner

My email is Johnny.Ensign@gmail.com

#12 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 24 June 2006 - 05:39 PM

did you echo $sql ?

does it show something like

select * from registry where user='blah'

on your screen, or does it show

select * from registry where user=''

and if it shows the first, copy and paste it into phpmyadmin and see if you get a result.

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#13 JP128

JP128
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationWisconsin

Posted 24 June 2006 - 10:11 PM

It doesnt echo anything.
-----------------------------------------------------------------------
John Ensign - Age 16 - PHP Learner

My email is Johnny.Ensign@gmail.com

#14 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 24 June 2006 - 10:26 PM

Do you mean that echo $sql produces absolutely nothing whatsoever?????
Legend has it that reading the manual never killed anyone.
My site

#15 JP128

JP128
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationWisconsin

Posted 25 June 2006 - 05:03 AM

correct


Does anyone have like a messenger that I can talk to them directly? It would be much faster.
-----------------------------------------------------------------------
John Ensign - Age 16 - PHP Learner

My email is Johnny.Ensign@gmail.com

#16 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 June 2006 - 05:18 AM

Can you post you're new script?

Ken

#17 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 June 2006 - 06:26 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#18 JP128

JP128
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationWisconsin

Posted 25 June 2006 - 08:26 AM

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();
?>
-----------------------------------------------------------------------
John Ensign - Age 16 - PHP Learner

My email is Johnny.Ensign@gmail.com

#19 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 June 2006 - 08:54 AM

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]

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users