Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: MySQL not inserting into database?

  1. #1
    War of the Lands is offline x10Hosting Member War of the Lands is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    11

    MySQL not inserting into database?

    Code:

    PHP Code:
    <?php
    if (isset($_POST['submit'])) {
    $pass=$_POST['pass'];
    $user=$_POST['user'];
    $email=$_POST['email'];
         }
    else {
         
    register();
         require_once 
    "footer.php";
         exit;
         }
    $resultmysql_query("SELECT * FROM 'login' WHERE (username = '$user')");
    $checkmysql_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(); 
         
    $resultmysql_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

  2. #2
    shades is offline x10Hosting Member shades is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    3

    Re: MySQL not inserting into database?

    Change
    Code:
    $check= mysql_num_rows('$result');
    to
    Code:
    $check= mysql_num_rows($result);

  3. #3
    War of the Lands is offline x10Hosting Member War of the Lands is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    11

    Re: MySQL not inserting into database?

    I did that and it still comes up with the warning. Im soo confused at the momment LOL!

  4. #4
    shades is offline x10Hosting Member shades is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    3

    Re: MySQL not inserting into database?

    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?

  5. #5
    War of the Lands is offline x10Hosting Member War of the Lands is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    11

    Re: MySQL not inserting into database?

    Please if you can get it to work I can then get on with the rest of the login system.

  6. #6
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: MySQL not inserting into database?

    change
    PHP Code:
    $resultmysql_query("INSERT INTO login VALUES('$user', '$pass2', '$email', '$active')");

    // to

    $resultmysql_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

  7. #7
    sunils's Avatar
    sunils is offline x10 Spammer sunils is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Chennai ,India
    Posts
    2,264

    Re: MySQL not inserting into database?

    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 {
    .......................
    }
    [LEFT][B]Sunil Sankar
    -------------------------------------------------------------------------

  8. #8
    rima123 is offline x10Hosting Member rima123 is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    9

    Re: MySQL not inserting into database?

    $check= mysql_num_rows('$result');

    remove ' ' quotes around '$result'

  9. #9
    War of the Lands is offline x10Hosting Member War of the Lands is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    11

    Re: MySQL not inserting into database?

    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 by War of the Lands; 09-10-2008 at 12:23 PM. Reason: Automerged Doublepost

  10. #10
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: MySQL not inserting into database?

    Try this. I make the assumption that ID is not set to auto increment, and also that footer.php connects to your database.
    PHP Code:
    <?php
    if (isset($_POST['submit'])) {
    $pass=$_POST['pass'];
    $user=$_POST['user'];
    $email=$_POST['email'];
         }
    else {
         
    register();
         require_once 
    "footer.php";
         exit;
         }
    $resultmysql_query("SELECT * FROM 'login' WHERE (username = '$user')");
    $checkmysql_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";
    ?>
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

Closed Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  3. How to create MySQL database and user
    By Jesse in forum Tutorials
    Replies: 11
    Last Post: 06-04-2008, 12:25 PM
  4. PHP BB 2.0.16 Manual instalation
    By GFIV in forum Free Hosting
    Replies: 8
    Last Post: 09-14-2005, 12:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers