1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Parse error that i cannot make sense of

Discussion in 'PHP' started by Dirty-Rockstar, Aug 14, 2007.

  1. #1
    Now bear with me, the page itself probably wont work. It is probably wrong. But you have to learn some way right?..anyway above is the error and below is the entire page. Print seems fine. must be something above. i perfer print over echo

    I just threw the page together based on what i learned so far. Soooo if it makes no sense thats ok...I just cannot see this error. helpage?

    thanks = )

    
    
    <?
    session_start();
    
    //required pages
    require "connect.php";
    
    // make connect global on the page
    global $connect;
    
    
    // makes the ip a variable
    $ip = $_SERVER['REMOTE_ADDR'];
    
    
    // If username is posted it sets it to a var
    if($_POST['username'])
    {
    $username=$_POST['username'];
    }
    
    
    // queries db to see if the username already exists
    $userquery=mysql_query("SELECT * FROM users WHERE loginname='{$username}'",$connect);
    
    
    
    if(mysql_num_rows($userquery))
    {
    Print "Username currently in use. Choose something else.";
    }
    
    
    //checks to see if the password and confirm passwords dont match
    else if($_POST['password'] != $_POST['confirmpassword'])
    {
    print "Passwords did not match";
    }
    
    else
    {
    
    // inserts into the database
    mysql_query("INSERT INTO users (loginname, loginpassword, ip) VALUES ( '{$username}',
    '{$_POST[password]}', '{$ip}');
    
    }
    
    
    
    
    
    else
    {
    
    print "
    <center><table>
    <tr>
    <td><form action=register.php method=post>Username:</td>
    <td><input type=text name=username></td>
    </tr>
    <tr>
    <td>Password: </td>
    <td><input type=password name=password></td>
    </tr>
    <tr>
    <td>Confirm Password:</td>
    <td><input type=password name=confirmpassword></td>
    </tr>
    <td>Email:</td>
    <td><input type=text name=email></td>
    </tr>
    <td>Promo Code:</td>
    <td><input type=text name=promo></td>
    </table>
    
    
    <input type=submit value=Submit></form>";
    }
    print "</body></html>";
    ?>
    PHP:
     
    Dirty-Rockstar, Aug 14, 2007 IP
    void likes this.
  2. void

    void Peon

    Messages:
    119
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    // inserts into the database
    mysql_query("INSERT INTO users (loginname, loginpassword, ip) VALUES ( '{$username}',
    '{$_POST['password']}', '{$ip}'");
    PHP:
    You need the quotation mark to end your query, and the apostrophes around password.
     
    void, Aug 14, 2007 IP
    Dirty-Rockstar likes this.
  3. Dirty-Rockstar

    Dirty-Rockstar Guest

    Messages:
    252
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ^^ thanks for resolving my first issue. 1+ for you. now i came into a second problem. I cannot insert into the database anything. i checked the field names in the db. they match up. and the table name is users so thats right too. there is already one user in there i manually put in myself to start the auto increment of a field called id.
    I also assigned that query to $query and tried to print it and nothing happened(blank page).

    ps, i recycled this thread as not to spam up your forum = )

    can someone please tell me whats wrong?
    excuse the notes :p im learning = )

    
    
    <?session_start();
    
    //required pages
    require "connect.php";
    
    // makes the ip a varialbe
    $ip = $_SERVER['REMOTE_ADDR'];
    
    
    // If username is set it sets it to a var
    //first if
    if($_POST['username'])
    {
    $username=$_POST['username'];
    // queries db to see if the username already exists
    $userquery=mysql_query("SELECT * FROM users WHERE loginname='{$username}'",$connect) or die(mysql_error());
    
    //nested if in the first if
    if(mysql_num_rows($userquery))
    {
    
    Print "Username currently in use. Choose something else.";
    }//close of nested if
    
    
    //checks to see if the password and confirm passwords dont match
    //still in first if
    elseif($_POST['password'] != $_POST['confirmpassword'])
    {
    print "Passwords did not match";
    }//close of elseif
    
    //checks to see if username box or password box are blank. it can be "or" because it only takes 1 blank to kill the signup
    elseif($_POST['password']=='' || $_POST['username']=='')
    {
    print "Your username or password was blank";
    }//close of elseif
    
    /*
    After checking for existing username, matching passwords
    and blank username/password fields and all that passes inspection this next part
    inserts the information from the page into the db
    */
    
    else
    {
    
    // inserts into the database
    
    mysql_query("INSERT INTO users (loginname, loginpassword, ip) VALUES ( '{$username}',
    '{$_POST['password']}', '{$ip}'")or print "POOOF didnt work";
    
    
    }
    }//close of first if to bunch it all together
    
    
    //what happens if nothing above is happening.pretty much the signup page
    else{
    
    
    
    
    print "
    <center><table>
    <tr>
    <td><form action=register.php method=post>Username:</td>
    <td><input type=text name=username></td>
    </tr>
    <tr>
    <td>Password: </td>
    <td><input type=password name=password></td>
    </tr>
    <tr>
    <td>Confirm Password:</td>
    <td><input type=password name=confirmpassword></td>
    </tr>
    
    </table>
    
    
    <input type=submit value=Submit></form>";}
    
    print "</body></html>";?>
    
    PHP:
     
    Dirty-Rockstar, Aug 14, 2007 IP
  4. Twade Media

    Twade Media Banned

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    if(mysql_num_rows($userquery))

    this doesnt make sense for a start..

    You will need to set it to apply to something

    if(mysql_num_rows($userquery) == "1") for example
     
    Twade Media, Aug 14, 2007 IP
    Dirty-Rockstar likes this.
  5. void

    void Peon

    Messages:
    119
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try replacing the first line with this and let me know what happens.
    <?
    error_reporting(E_ALL);
    ini_set('display_errors','1');
    session_start();
    PHP:
     
    void, Aug 14, 2007 IP
  6. Dirty-Rockstar

    Dirty-Rockstar Guest

    Messages:
    252
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thank you both for your replies but this fixed it.
    first i printed out what i wanted to be inserted to see if it was actually grabbing it. and it was. so then i knew it was the insert. after messing around with it i came up with this and it worked


    mysql_query("INSERT INTO users (loginname, loginpassword, ip) VALUES ( '{$username}',
    '{$_POST['password']}', '{$ip}')")or die(mysql_error());
    PHP:
    I didnt seem to close ("

    as far as
    
    if(mysql_num_rows($userquery))
    {
    
    Print "Username currently in use. Choose something else.";
    PHP:

    I see where your coming from. but the code works anyway. ill put a notation to look at it later but for now its not an issue. both 1+ for helping me if you never got 1+ from me in the past and im denied it.

    thanks again
     
    Dirty-Rockstar, Aug 14, 2007 IP