I have this, and I'm not sure what I'm getting wrong:
<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
Offline
actually, it means that the argument you're giving it isn't a valid query result. Try echoing $checkuser and see what it is.
Offline
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.
Offline
ssss wrote:
set the variable to waht $checkuser = 's ?
Variables aren't the problem. It's not reading the mysql_num_rows() script.
Offline
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
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!
)
Offline
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)
Offline
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.
Offline
I found your problem, you are using 'username' instead of 'user'.
$checkuser = mysql_query("SELECT username FROM login WHERE username='$username'", $link);Should be
$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.
Last edited by Magnie (2011-10-13 21:52:24)
Offline
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.![]()
Thank you! Now it works!!! Registrations will be open soon, big thanks to Magnie!
Offline
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);
Offline