Help with PHP code

Discussion in 'Software' started by Tremour, Feb 17, 2004.

  1. Tremour

    Tremour Private E-2

    PHP:
    i made this code but when ever i try to use it the screen comes out blank
     
     
    here's the code : 
     
    <?php
     
    require_once('data_valid.php');
     
    //create short variable names
     
    $email=$HTTP_POST_VARS['email'];
     
    $username=$HTTP_POST_VARS['username'];
     
    $password=$HTTP_POST_VARS['password'];
     
    $password2=$HTTP_POST_VARS['password2'];
     
    // start session which may be needed later
     
    // start it now because it must go before headers
     
    session_start();
     
     
     
    // check forums are filled in
     
    if(!filled_out($HTTP_POST_VARS))
     
    {
     
    echo 
    'You have not compleated the forms - Please go back and'
     
    .' and try again.';
     
    exit;
     
    }
     
    // Fake e-mail address
     
    if(!valid_email($email))
     
    {
     
    echo 
    'That is not a valid email address. Please go back '
     
    .' and try again.';
     
    exit;
     
    }
     
    // passwords not the same 
     
    if($passwd!= $passwd2)
     
    {
     
    echo 
    'The passwords you entered do not match - please go back'
     
    .' and try again.';
     
    exit;
     
    }
     
    // check password length is ok
     
    // ok if username truncates, but passwords will get
     
    // munged if they are too long.
     
    if(strlen($passwd)<||strlen($passwd)>16)
     
    {
     
    echo 
    'Your password must be between 6 and 16 characters.'
     
    .'Please go back and try again.';
     
    exit;
     
    // attempt to register
     
    $db_conn=mysql_connect('mysql''myusername''mypassword');
     
    mysql_select_db('main_site'$db_conn);
     
    $query"INSERT INTO `tremour` ( `username` , `password` , `email` ) 
     
    VALUES('
    $username',PASSWORD( '$password' ), '$email')";
     
    $result=mysql_query($query$db_conn);
     
    return 
    $result
     
    }
     
    // register session variable 
     
    $HTTP_SESSION_VARS['valid_user']= $username;
     
    // provide link to members page
     
    echo 'Your registration was successful.';
     
    }else
     
    {
     
    // otherwise provide link back, tell them to try again
     
    echo 'There is a problem with the website and/or database, please contact'
     
    .' the webmaster and try again later.';
     
    exit;
     
    }
     
    ?>
     

    is there anyone that can tell me the problem?, thanks in advance (the myusername and mypassword are to protect my details, they arn't used in the script)
     
    Last edited by a moderator: Feb 17, 2004
  2. ChViRuS

    ChViRuS Private E-2

    Well it could just be me (that code is awfully hard to follow without indents), but I think you have an extra } in there. Im assuming there should be another "if" statement.

    Here is where I think it all is happening:

    // register session variable

    $HTTP_SESSION_VARS['
    valid_user']= $username;

    // provide link to members page

    echo '
    Your registration was successful.';

    }else

    {


    So, Im guessing that you need an if statment at the top of this
    code. (excuse the line breaks, this editor seems to have
    broken).

    Normally, an error like that would appear as a parse error.
    Hence I can only think of two reasons why it isnt reporting this:

    Firstly, you havent shown your entire code, and there is infact
    an EXTRA curly bracket above this code somewhere, hence making
    the compiler think its all ok (if so, go back and check).
    Otherwise, I would suggest that your php settings on your server
    have their error reporting turned down too low... I would
    suggest turning them back up to their highest setting!!
    If you dont have access to your php config settings on your
    server, ask your server admin.
     
  3. Tremour

    Tremour Private E-2

    Thanks for your help, i found the problem and i added a if statement

    if ($result === true)
    {
    // register session variable
    $HTTP_SESSION_VARS['valid_user']= $username;
    // provide link to members page
    echo 'Your registration was successful.';

    thats made the code work fine now.
     
  4. goldfish

    goldfish Lt. Sushi.DC

    Are you testing this on a 'production' server? If not then you might wanna try turning on all errors (E_ALL) in php.ini. That way you can iron out any notices before you upload to a live server.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds