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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Damn you syntax error, need help please (:

    Hi guys, i need some help here with my php code. Im trying to make a login and regestration site, havn't gotten very far though. I tried to fix the problem on my own, by reading alot about it, but still it gives me this error.
    im getting a "Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\afsluttende projekt\test.php on line 5"

    and heres my code:
    PHP Code:
    <?php

    $username 
    $_POST ['username']

    $link mysql_connect ('localhost','root',''); //this is line 5
    if (!$link) {
        die(
    'Could not connect: ' mysql_error());
    }
    echo 
    'Connected successfully';
    mysql_close($link);

    $db mysql_select_db ('phplogin');
    if (!
    $db) {
        die(
    'Could not find database: ' mysql_error());
    }

    $query mysql_query ("SELECT * FROM phplogin WHERE username = {$_POST ['username']}"$link) or die (mysql_error());
    mysql_query($query);

    $num_row mysql_num_rows ($query);
    echo (
    $num_row);

    ?>
    Im just trying to make it spit out a username and password for now, one step at the time right :p
    ty in advanced
    Last edited by spiralzone; 03-20-2011 at 04:08 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    $username assignment is missing a semi-colon at the end.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    spiralzone (03-20-2011)

  • #3
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,302
    Thanks
    4
    Thanked 204 Times in 201 Posts
    You are missing a semi-colon at the end of this line $username = $_POST ['username'];
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    spiralzone (03-20-2011)

  • #4
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    oh my bad, must have missed that, ty
    but now i get a "Notice: Undefined index: username in C:\wamp\www\afsluttende projekt\test.php on line 3"? can you help me with this also?(:

  • #5
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,302
    Thanks
    4
    Thanked 204 Times in 201 Posts
    Any time you are going to use a form variable, either POST or GET, check to see if it is set before blindly retrieving or using it.

    PHP Code:
    $username '';
    if (isset(
    $_POST['username '])) {
       
    $page mysql_escape_string($_POST['username ']);

    What you default $username to, blank or something else, depends on whether or not the rest of your code depends on it and how it will behave if it is an empty string as I showed above.
    Dave .... HostMonster for all of your hosting needs

  • #6
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thx alot, that fixed the problem! it had been buggin me for some time now, ty!


  •  

    Tags for this Thread

    Posting Permissions

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