MySQL not inserting into database?

Status
Not open for further replies.

War of the Lands

New Member
Messages
11
Reaction score
0
Points
0
Code:

PHP:
<?php
if (isset($_POST['submit'])) {
$pass=$_POST['pass'];
$user=$_POST['user'];
$email=$_POST['email'];
     }
else {
     register();
     require_once "footer.php";
     exit;
     }
$result= mysql_query("SELECT * FROM 'login' WHERE (username = '$user')");
$check= mysql_num_rows('$result');
if ($check != 0) {
    echo "'$user' has already been taken, please try another username!";
    register();
    require_once "footer.php";
    exit;
     }
else {
     $pass2=md5($pass);
     $active=rand(); 
     $result= mysql_query("INSERT INTO login VALUES('$user', '$pass2', '$email', '$active')");
     
     $to=$email;
     $subject="Activation - War of the Lands";
     $message="Your activation link: $active \r\n";
     $message.="Copy this code into the input box on this page: \r\n";
     $message.="http://www.warofthelands.x10hosting.com/V1/active.php";
     $header="From: no-reply@warofthelands.x10hosting.com";
  
     mail($to, $subject, $message, $header);
     
     echo "<br>You have been sent your activation link. You need to activate your account before you can login!<br>";
     
      }
require_once "footer.php";
?>

When i fill the form out and register it won't insert into the database and I also get this error when counting:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/warland/public_html/V1/register.php on line 20
 

shades

New Member
Messages
3
Reaction score
0
Points
0
Change
Code:
$check= mysql_num_rows('$result');
to
Code:
$check= mysql_num_rows($result);

:)
 

shades

New Member
Messages
3
Reaction score
0
Points
0
Hmm, that's odd, I did it on my testing server, and it came up with the error when I had the quotes around it. Would you like me to rewrite it?
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
change
PHP:
$result= mysql_query("INSERT INTO login VALUES('$user', '$pass2', '$email', '$active')");

// to

$result= mysql_query("INSERT INTO login (username, password, email, active) VALUES('$user', '$pass2', '$email', '$active')") or mysql_error();
and change the fields in the first set of ()'s to match the proper fields in your database.

with your mysql query, if the first field is id, the second is username, then password, email, and then active, then you're query won't execute properly.

-xP
 

sunils

New Member
Messages
2,266
Reaction score
0
Points
0
Which line in the file register.php is line 20.

If you can point out that in the above code snippet that would be usefull.

Here are my suggestion...

Change this lines

$result= mysql_query("SELECT * FROM 'login' WHERE (username = '$user')");
$check= mysql_num_rows('$result');

if ($check != 0) {
.....................
}
else {
.......................
}

to

$check= mysql_query("SELECT count(*) FROM 'login' WHERE (username = '$user')");
if ($check!= 0) {
.....................
}
else {
.......................
}
 

rima123

New Member
Messages
9
Reaction score
0
Points
0
$check= mysql_num_rows('$result');

remove ' ' quotes around '$result'
 

War of the Lands

New Member
Messages
11
Reaction score
0
Points
0
It still wont insert the data into the database so could someone write me a mysql query incase im doing it wrong. There are 5 fields that go in this order ID, username, password, email, active. This is really starting to annoy me now!!!
Edit:
Is anyone going to help me? I cant get on with the rest of the coding until i get help. Please someone help!!!
 
Last edited:

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
Try this. I make the assumption that ID is not set to auto increment, and also that footer.php connects to your database.
PHP:
<?php
if (isset($_POST['submit'])) {
$pass=$_POST['pass'];
$user=$_POST['user'];
$email=$_POST['email'];
     }
else {
     register();
     require_once "footer.php";
     exit;
     }
$result= mysql_query("SELECT * FROM 'login' WHERE (username = '$user')");
$check= mysql_num_rows('$result');
if ($check != 0) {
    echo "'$user' has already been taken, please try another username!";
    register();
    require_once "footer.php";
    exit;
     }
else {
     $pass2=md5($pass);
     $active=rand();
     $query = "INSERT INTO login (ID,username,password,email,active) VALUES('$id','$username','$password','$email','$active')";
     mysql_query($query) or die(mysql_error());
     
     $to=$email;
     $subject="Activation - War of the Lands";
     $message="Your activation link: $active \r\n";
     $message.="Copy this code into the input box on this page: \r\n";
     $message.="http://www.warofthelands.x10hosting.com/V1/active.php";
     $header="From: no-reply@warofthelands.x10hosting.com";
  
     mail($to, $subject, $message, $header);
     
     echo "<br>You have been sent your activation link. You need to activate your account before you can login!<br>";
     
      }
require_once "footer.php";
?>
 

sunils

New Member
Messages
2,266
Reaction score
0
Points
0
Closing the thread since the problem is solved.
The author can reopen the thread, if he/she wants some more clarification.
 
Status
Not open for further replies.
Top