This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-10-12 11:41:47

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

MySQL ERROR: Doh!

I have this, and I'm not sure what I'm getting wrong:

Code:

<link rel="stylesheet" type="text/css" href="global.css" />
<?php
if(isset($_POST['submit'])) {

include "demo.html";

//Database Information
 
$dbhost = '*';
$dbuser = '*'; 
$dbpass = '*';
$dbname = '*';
 
//Connect to database
 
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$email = $_POST['email'];    
$username = $_POST['username'];
$password = ($_POST['password']);
 
// lets check to see if the username already exists
 
$link = mysql_connect("*", "*", "*");
mysql_select_db("*", $link);
 
$checkuser = mysql_query("SELECT username FROM login WHERE username='$username'", $link);

$num_rows = mysql_num_rows($checkuser); //this is line 30
 
if($username_exist > 0){
    echo "<p>The username $username is already taken. Please retry.</p>";
    unset($username);
    include 'registration.html';
    exit();
}
 
// lf no errors present with the username
// use a query to insert the data into the database.

$ip = $_SERVER['REMOTE_ADDR'];

$query = "INSERT INTO login (user, pass, ban, email, ip)
VALUES('$username', '$password', 'false', '$email', '$ip')";
mysql_query($query) or die(mysql_error());
mysql_close();
 
echo "<p>You are now registered! Your account details have been sent to $email!</p>";
   
// mail user their information
 
$yoursite = 'Mini Universe Service';
$webmaster = 'Mini Universe Website Service';
$youremail = '*';
   
$subject = "Mini Universe - Account Details";
$message = "Thank you for registering at Mini Universe! You can login now with the following details:

Username: $username
Password: $password

We hope you have fun sharing, and downloading planets!";
   
mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());
   
echo "<p>You are ready to log in! We have sent your info to your email.</p>";
 } else {
 header('Location: http://www.plaxon.comyr.com/error404.php');
 }
?>

It's basicly a registration form. The error is at line 30. I keep getting: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a5292800/public_html/register.php on line 30
That means that mysql_num_rows() isn't a valid code, even though it works in my other codes. So I don't get what it wants me to do  sad


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#2 2011-10-12 19:41:21

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: MySQL ERROR: Doh!

actually, it means that the argument you're giving it isn't a valid query result. Try echoing $checkuser and see what it is.


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#3 2011-10-13 02:54:29

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: MySQL ERROR: Doh!

ScratchReallyROCKS wrote:

actually, it means that the argument you're giving it isn't a valid query result. Try echoing $checkuser and see what it is.

That wouldn't work, because then it would echo, and not set the variable. The variable needs to be set, because it is used later on in the script.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#4 2011-10-13 02:56:41

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: MySQL ERROR: Doh!

set the variable to waht $checkuser = 's ?


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#5 2011-10-13 02:59:58

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: MySQL ERROR: Doh!

ssss wrote:

set the variable to waht $checkuser = 's ?

Variables aren't the problem. It's not reading the mysql_num_rows() script.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#6 2011-10-13 03:09:22

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: MySQL ERROR: Doh!

bleh.


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#7 2011-10-13 10:43:38

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: MySQL ERROR: Doh!

WindowsExplorer wrote:

ssss wrote:

set the variable to waht $checkuser = 's ?

Variables aren't the problem. It's not reading the mysql_num_rows() script.

Actually, it is the variables. The command has no problem, something you put into the variable doesn't work with the command.

Offline

 

#8 2011-10-13 10:46:10

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: MySQL ERROR: Doh!

Magnie wrote:

WindowsExplorer wrote:

ssss wrote:

set the variable to waht $checkuser = 's ?

Variables aren't the problem. It's not reading the mysql_num_rows() script.

Actually, it is the variables. The command has no problem, something you put into the variable doesn't work with the command.

Well what? I put the registration forum under mentainence until this is fixed. (Lucky - you managed to slip in a registration beforehand!  tongue )


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#9 2011-10-13 17:53:12

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: MySQL ERROR: Doh!

I remember when I used MySQL with a website I made, and I had to put backticks (`) around the the tables and data fields. If this matters for you, then your query should look like this:

SELECT `username` FROM `login` WHERE `username` = '$username'

EDIT:
Yep, I bet that is the problem, seeing as you're using 000webhost and I was too.

Last edited by ScratchReallyROCKS (2011-10-13 17:57:53)


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#10 2011-10-13 19:13:58

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: MySQL ERROR: Doh!

ScratchReallyROCKS wrote:

I remember when I used MySQL with a website I made, and I had to put backticks (`) around the the tables and data fields. If this matters for you, then your query should look like this:

SELECT `username` FROM `login` WHERE `username` = '$username'

EDIT:
Yep, I bet that is the problem, seeing as you're using 000webhost and I was too.

Can't say I've ever heard of that problem before.


http://i.imgur.com/zeIZW.png

Offline

 

#11 2011-10-13 21:50:58

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: MySQL ERROR: Doh!

I found your problem, you are using 'username' instead of 'user'.

Code:

$checkuser = mysql_query("SELECT username FROM login WHERE username='$username'", $link);

Should be

Code:

$checkuser = mysql_query("SELECT user FROM login WHERE user='$username'", $link);

Can't believe I missed that.

Edit: And we were correct that it was the query/variable that had the incorrect data.  wink

Last edited by Magnie (2011-10-13 21:52:24)

Offline

 

#12 2011-10-14 03:09:04

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: MySQL ERROR: Doh!

Magnie wrote:

I found your problem, you are using 'username' instead of 'user'.

Code:

$checkuser = mysql_query("SELECT username FROM login WHERE username='$username'", $link);

Should be

Code:

$checkuser = mysql_query("SELECT user FROM login WHERE user='$username'", $link);

Can't believe I missed that.

Edit: And we were correct that it was the query/variable that had the incorrect data.  wink

Thank you! Now it works!!! Registrations will be open soon, big thanks to Magnie!


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#13 2011-10-14 03:17:27

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: MySQL ERROR: Doh!

wait. im still getting the error  sad


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#14 2011-10-14 10:10:47

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: MySQL ERROR: Doh!

Really?

Oh yeah, the $link is not needed in the $num_rows = mysql_query($checkuser, $link); so switch it to $num_rows = mysql_query($checkuser);  smile

Offline

 

Board footer