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.
Page 1 of 3 123 LastLast
Results 1 to 15 of 31

Thread: php error help

  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts

    php error help

    Parse error: syntax error, unexpected T_STRING in [path removed]/checklogin.php on line 4

    Code:
    <?php
    
    include("dbsettings.php")
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    
    
    $sql=("SELECT * FROM tbl_name WHERE username='$username' AND password='$md5password'");
    
    
    
    $result=mysql_query($sql);
    
    if (mysql_num_rows($result) == 1)
    
    {
    
    
    $_SESSION['username'];
    $_SESSION['password'];
    
    echo '<META HTTP-EQUIV="Refresh" Content="0" URL="account.php?success">'; 
    }
    else {
    echo "Wrong username/password. Please try again.";
    }
    ?>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    include("dbsettings.php")

    missing semicolon at the end of that line ...

    include("dbsettings.php");


    .

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,447
    Thanks
    71
    Thanked 102 Times in 101 Posts
    This is a triple post by the same user, with the same code.

  • #4
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    still not working



    Code:
    <?php
    
    include("dbsettings.php");
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    
    
    $sql=("SELECT * FROM tbl_name WHERE username='$username' AND password='$md5password'");
    
    
    
    $result=mysql_query($sql);
    
    
    if(mysql_num_rows($result) == 1)
    
    {
    
    
    $_SESSION['username'];
    $_SESSION['password'];
    
    echo '<META HTTP-EQUIV="Refresh" Content="0" URL="account.php?success">'; 
    }
    else {
    echo "Wrong username/password. Please try again.";
    }
    ?>

  • #5
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    Amcf, you need to stop triple posting. Its against the rules here and will get you banned. That is def. not something you want. To answer your question, or atleast try, You should definitely have a check wherever you can. One such check is right after the mysql_query. You need to check if its true before you use mysql_num_rows, that will tell you if there is a problem with the query. Which should show you that your query is wrong.

    PHP Code:
    <?php
    include("dbsettings.php");
    mysql_connect("$host""$username""$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
     
     
    $sql="SELECT * FROM tbl_name WHERE username= '" $username"' AND password='"$md5password ."'";
     
    $result=mysql_query($sql);
     
    // do the check
    if($result) {
     
    if(
    mysql_num_rows($result) == 1)
     
    {
     
     
    $_SESSION['username'];
    $_SESSION['password'];
     
    echo 
    '<META HTTP-EQUIV="Refresh" Content="0" URL="account.php?success">'
    }
    else {
    echo 
    "Wrong username/password. Please try again.";
    }
    } else {
     echo 
    "The query is not true.";
    }
    ?>
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #6
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thanks for replying, I used your code but now I'm getting this error

    Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/friendko/public_html/development/load/dologin.php on line 29

  • #7
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Parse error-help

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/friendko/public_html/development/load/execlogin.php on line 18



    Code:
    <?php
    ob_start();
    include("dbsettings.php");
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    // Define $myusername and $mypassword 
    $username=$_POST['username']; 
    $password=$_POST['password'];
    
    // To protect MySQL injection (more detail about MySQL injection)
    $username = stripslashes($username);
    $password = stripslashes($mypassword);
    $username = mysql_real_escape_string($myusername);
    $password = mysql_real_escape_string($mypassword);
    
    $sql="SELECT * FROM $tbl_name WHERE username='$_POST['username']' AND password='".md5($_POST['password'])."'";
    $result=mysql_query($sql);
    
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row
    
    if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    $_SESSION("username");
    $_SESSION("password"); 
    echo '<META HTTP-EQUIV="Refresh" Content="0" URL="account.php?success">'; 
    }
    else {
    echo "Wrong Username or Password";
    }
    
    ob_end_flush();
    ?>

  • #8
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    There is nothing wrong with the code I provided, to my knowledge Are you sure you used everything I have in that code box?? Try again and tell me if its the same error.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #9
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Ok i just realize something, I md5 the password on the register form, so i guess my question is: How do i compare the user plain text password to its equivalent on the db?

  • #10
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    You shoud use md5 again in this script. See example below.

    PHP Code:
    <?php
    include("dbsettings.php");
    mysql_connect("$host""$username""$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
     
    $username mysql_real_escape_string($_POST['username']);
    $password md5(mysql_real_escape_string($_POST['password']));
    $sql="SELECT * FROM tbl_name WHERE username= '" $username"' AND password='"$password ."'";
     
    $result=mysql_query($sql);
     
    // do the check
    if($result) {
     
    if(
    mysql_num_rows($result) == 1)
     
    {
     
     
    $_SESSION['username'];
    $_SESSION['password'];
     
    echo 
    '<META HTTP-EQUIV="Refresh" Content="0" URL="account.php?success">'
    }
    else {
    echo 
    "Wrong username/password. Please try again.";
    }
    } else {
     echo 
    "The query is not true.";
    }
    ?>
    Last edited by Chris Hick; 09-15-2011 at 05:50 AM.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #11
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    ok i made the necessary corrections, now i just receiving "The query is not true."

  • #12
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    Recopy what I have in the code above and see what it says. I had to make a correction of my own. Tell me what it says then.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #13
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Ok, well i added a $ before table_name

    $sql="SELECT * FROM tbl_name WHERE username= '" . $username. "' AND password='". $password ."'";

    Now, I get a different error msg:

    Wrong username/password. Please try again.

  • #14
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    Then, the script is working if you are getting that message. This means you are incorrectly putting your username or password.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #15
    Regular Coder
    Join Date
    May 2007
    Posts
    100
    Thanks
    16
    Thanked 11 Times in 11 Posts
    Wrap $_POST['username'] in curly brackets on line 18.

    $sql="SELECT * FROM $tbl_name WHERE username='{$_POST['username']}' AND password='".md5($_POST['password'])."'";


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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