Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts

    mysql query not selecting correctly

    PHP Code:
    <?php session_start(); ?>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Account Dashboard</title>
    </head>
    <body>
    <?php
    include('dbsettings.php');

    $con mysql_connect("$host","$user","$password");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("$db_name"$con);

    $username=$_POST['username'];
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];
    $address=$_POST['address'];
    $email=$_POST['email'];
    $password=$_POST['password'];
    $pass2=$_POST['password2'];
    $account=$_POST['account'];
    $secretquestion1=$_POST['secretquestion1'];
    $secretanswer1=$_POST['secretanswer1'];
    $datedate("m-d-y");

    $result mysql_query("SELECT * FROM $tbl_name WHERE email='$email'");

    while(
    $row mysql_fetch_array($result))
      {
      echo 
    $row['firstname'] . " " $row['lastname'];
      echo 
    "<br />";
      }

    mysql_close($con);
    ?>
    <a href="logout.php"> Log Out </a>
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,413
    Thanks
    68
    Thanked 102 Times in 101 Posts
    Where is your post method at?

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <titleLogin</title>
    </head>
    <body>
     
    <form method="POST" action="dologin.php">
      Username: <br /><input type="text" name="username" size="30" style="width:250px; height:50px;  font-size: 18px;"> <br />
      Password:<br /><input type="password" name="password" size="30" style="width:250px; height:50px; font-size: 18px;">
      <br /> <br />
      <div align="left">
        <p><input type="submit" value="Login" /></p>
        
     
    </body>
    </html>

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Where is the definition of $tbl_name ??

    I don't see that you ever assign to a variable of that name.

    And, given the <form> you showed, the *ONLY* $_POST values you can get are
    Code:
    $username=$_POST['username']; 
    $password=$_POST['password'];
    Which means that your use of $email is also invalid.

    Looks to me like you are trying to piece together code from two different places and you are trying to put a square peg into a round hole.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts
    $tbl_name is inside dbsettings.php
    here is the code for the register, which contains the $email value


    PHP Code:
    <?php
    session_start
    ();
    include(
    'dbsettings.php');
    // Connect to server and select database.
    mysql_connect("$host""$username""$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");

    // Get values from form

    $username=$_POST['username'];
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];
    $address=$_POST['address'];
    $email=$_POST['email'];
    $password=$_POST['password'];
    $pass2=$_POST['password2'];
    $account=$_POST['account'];
    $secretquestion1=$_POST['secretquestion1'];
    $secretanswer1=$_POST['secretanswer1'];
    $datedate("m-d-y");


        function 
    rand_string$length ) {
            
    $chars "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";    
            
            
    $size strlen$chars );
            for( 
    $i 0$i $length$i++ ) {
                
    $str .= $charsrand0$size ) ];
            }
            
            return 
    $str;
        }
    $activationkeyrand_string45 );

    //md5 password
    $md5password=md5("$password");





    // Insert data into mysql 
    $sql="INSERT INTO $tbl_name(id, username, firstname, lastname, address, email, password, account, secretquestion1, secretanswer1, activationkey)
    VALUES('', '$username', '$firstname', '$lastname', '$address', '$email', '$md5password', '$account', '$secretquestion1', '$secretanswer1', '$activationkey')"
    ;
    $result=mysql_query($sql) or die(mysql_error());

    // if successfully insert data into database, displays message "Successful". 
    if($result){

    echo 
    "You have successfully registered. You will be redirected to the login page.";
     echo 
    '<META HTTP-EQUIV="Refresh" Content="3; URL=login.php">'
    }
    else
    echo 
    "There was a problem with the database. We'll fix this as soon as possible.";


    // close connection 
    mysql_close();
    ?>

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Fine, but that has NOTHING at all to do with the <form> you showed us in your post #3.

    *THAT* <form> will post *ONLY* username and password, so you can *NOT* use $email.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts
    okay then can i do:

    $result = mysql_query("SELECT * FROM $tbl_name WHERE username='$username");

    is that correctly formatted?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •