script help

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by CascadesAdmin, Jul 9, 2007.

  1. CascadesAdmin

    CascadesAdmin New Member

    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    I need help with this code:

    Using WHOLE new code, still need help

    PHP:
    <?
    //Database Information

    $dbhost "localhost";
    $dbname "cascades_sope1";
    $dbuser "cascades_sope1";
    $dbpass "hiimbob";

    //Connect to database

    mysql_connect $dbhost$dbuser$dbpass)or die("Could not connect: 

    "
    .mysql_error());
    mysql_select_db($dbname) or die(mysql_error());
    //end connecting to db


    //Storing Names
    //Secure (md5)

    $name $_POST['name'];
    $email $_POST['email'];    
    $username $_POST['username'];
    $password md5($_POST['password']);
    $emailpass = ($_POST['password']);
    //end secure
    //end storing names

    //checking if username already exists

    $checkuser mysql_query("SELECT username FROM users WHERE 

    username='
    $username'"); 

    $username_exist mysql_num_rows($checkuser);

    if (
    $username_exist 0){
       echo() 
    "I'm sorry but the username you entered has already been taken. 

     Please pick another one."
    ;
        unset(
    $username);
        include 
    'register.html';
        exit();
    }
    //end check

    //registrartion complete

    $query "INSERT INTO users (name, email, username, password)
    VALUES('
    $name', '$email', '$username', '$password')";
    mysql_query($query) or die(mysql_error());
    mysql_close());

    echo() 
    "You have successfully Registered";

    $yoursite ‘fanclub.cascades.exofire.net/;
    $webmaster ‘Cascades Admin’;
    $youremail ‘noreply@cascades.exofire.net’;

    $subject "You have successfully registered at $yoursite...";
    $message "Dear $name, you are now registered at our web site.  
             
                     PLEASE DO NOT REPLY TO THIS MESSAGE   

        To login, simply go to our web page and enter in the following 

    details in the login form:
        Username: 
    $username
        Password: 
    $emailpass
        
        Please print this information out and store it for future 

    reference.
        
        Thanks,
        
    $webmaster";
        
    mail($email$subject$message"From: $yoursite 

    <
    $youremail>\nX-Mailer:PHP/" phpversion());
        
    echo() 
    "Your information has been mailed to your email address.";


    ?>
    get this error message when I try to register to test

     
    Last edited: Jul 10, 2007
  2. Chris Z

    Chris Z Active Member

    Messages:
    5,603
    Likes Received:
    0
    Trophy Points:
    36
    try this:
    PHP:
    <?php 
    $database
    [dbserver]="localhost"
    $database[dbuser]="cascades_sope1"
    $database[dbname]="cascades_sope1"
    $database[dbpass]="Removed For Obvious Reasons"
    $table ="users"
     
    $connect mysql_connect($database[dbserver], $database[dbuser], $database[dbpass]); 
     
    $selectmysql_select_db($database[dbname]); 
    ?>
    or this:
    PHP:
    <?php 
    $database
    ['dbserver']="localhost"
    $database['dbuser']="cascades_sope1"
    $database['dbname']="cascades_sope1"
    $database['dbpass']="Removed For Obvious Reasons"
    $table ="users"
     
    $connect mysql_connect($database['dbserver'], $database['dbuser'], $database['dbpass']); 
     
    $selectmysql_select_db($database['dbname']); 
    ?>
     
    Last edited: Jul 9, 2007
  3. Kansy

    Kansy Community Advocate Community Support Prime Account

    Messages:
    2,622
    Likes Received:
    9
    Trophy Points:
    38
    mmm I think the first error is because an error with the DB login and user names.. try to delete your DB if its empty if not do a backup and create it another time... and chek again and if you need in the new DB upload all the tabls you have in the old

    I can't answer to the second error... Im sorry I have no Idea
     
  4. Zenax

    Zenax Active Member

    Messages:
    1,377
    Likes Received:
    4
    Trophy Points:
    38
    Chris Z is right on the connection script. You should leave the db server at local host:

    PHP:

    <?php 
    $database
    ['dbserver'] = 'localhost'
    $database['dbuser'] = 'cascades_sope1'
    $database['dbname'] = 'cascades_sope1'
    $database['dbpass'] = 'Removed For Obvious Reasons'
    $table 'users'
     
    $connect mysql_connect($database['dbserver'], $database['dbuser'], $database['dbpass']); 
     
    $selectmysql_select_db($database['dbname']); 
    ?> 


    As for your login script, I use the following:

    PHP:

    <?php
    session_start
    ();

    // Require once the DB script
       
    require_once ($_SERVER['DOCUMENT_ROOT']. '/config.php');

       if (
    $_POST['loginSubmit']) {
          
    // You *always!* need to validate user-supplied data when using it in MySQL queries!!
          // This isn't 100% secure, but it's definitely better than having nothing and being vulnerable to SQL injection.
          
    if(get_magic_quotes_gpc()) {
             if(
    ini_get('magic_quotes_sybase')) {
                 
    $username str_replace("''""'"$_POST['username']);
                 
    $password str_replace("''""'"$_POST['password']);
             } else {
                 
    $username stripslashes($_POST['username']);
                 
    $password stripslashes($_POST['password']);
             }
          } else {
              
    $username $_POST['username'];
              
    $password $_POST['password'];
          }
          
    $username mysql_real_escape_string($username);
          
    $password mysql_real_escape_string($password);
          
          
    $check mysql_query("SELECT * FROM `users` WHERE `users` = '$username' and `password` = '$password' LIMIT 1");
          
          
    // Counting the table row
          // If the result is matched then $username, $password must be row 1
          
    $count = @mysql_num_rows($check);
          
          
    // Logged in!
          
    if ($count == (int) 1) {
             
    $_SESSION['site_username'] = $username;
             
    $_SESSION['site_password'] = $password;
             
             echo 
    '<link rel="stylesheet" href="style.css" type="text/css" />
    <div align="center">Welcome '
    $_SESSION['site_username'] .'. You are now logged in!<br /><a href="members">Click Here to Continue</a></div>';

             
    $_GET['do'] = 'manualUnset';
             
    // Do whatever ?
          
    }
          else {
             echo 
    'Error: Wrong username or password specified. <br />';
          }
       }

       
    // If $_GET['do'] is set to 'manualUnset', do not show login form, user already logged in.
       
    switch ($_GET['do']) {
          case 
    'manualUnset':
             break;
          default:
    ?>
    <link rel="stylesheet" href="style.css" type="text/css" />
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <table width="90%" border="0" cellspacing="0" cellpadding="5">
         <tr>
          <td>Username:</td>
          <td>Password:</td>
         </tr>
         <tr>
          <td><input type="text" name="username" /></td>
          <td><input type="password" name="password" /> &nbsp; <input name="loginSubmit" type="submit" value="Login" class="button" /></td>
         </tr>
        </table>
        </form>
    <?php
          
    break;
       }
    ?> 


    If you have any more problems please let us know. Obviously the script I use is tailored to my needs, and if you want to use it you are more than welcome. All you would have to do is change around the names used in the script.

    Regards,
    Zenax
     
    Last edited: Jul 10, 2007
  5. CascadesAdmin

    CascadesAdmin New Member

    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    whole new script, whole new problem...
     
  6. Cubeform

    Cubeform New Member

    Messages:
    339
    Likes Received:
    0
    Trophy Points:
    0
    PHP error messages are always so unhelpful.

    Try this: If line 34 is the line with
    PHP:
       echo() "I'm sorry but the username you entered has already been taken. 
    try getting rid of the parentheses; you don't need them anyway. Do the same every time you use echo in your script.
     
    Last edited: Jul 10, 2007
  7. CascadesAdmin

    CascadesAdmin New Member

    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    no because the parentheses are needed in php4. If you search on google for echo php syntax, it will tell you that the correct way is echo()
     
  8. t2t2t

    t2t2t New Member

    Messages:
    690
    Likes Received:
    0
    Trophy Points:
    0
    http://ee2.php.net/manual/en/function.echo.php
    Believe in the manual! + you have totally wrong syntax! (The text has to be ("here") not () "here"
    Also, for line breaks, add <br />
     
  9. Chris Z

    Chris Z Active Member

    Messages:
    5,603
    Likes Received:
    0
    Trophy Points:
    36
    well if you need that, then it's supposed to be:
    PHP:
    echo('I\'m sorry but the username you entered has already been taken');
     
    Last edited: Jul 10, 2007
  10. Zenax

    Zenax Active Member

    Messages:
    1,377
    Likes Received:
    4
    Trophy Points:
    38
    I have always used:

    PHP:
    echo 'I\'m sorry but the username you entered has already been taken!';
    I never use parenthesis. I used too, but my scripts work without them, so I do not consider it a fundamental thing to include!
     
  11. Chris Z

    Chris Z Active Member

    Messages:
    5,603
    Likes Received:
    0
    Trophy Points:
    36
    Also, don't use:
    PHP:
    <?
    ?>
    ALWAYS USE:
    PHP:
    <?php
    ?>
    I've seen a few people run into problems just because they used the shorttag
     
  12. Zenax

    Zenax Active Member

    Messages:
    1,377
    Likes Received:
    4
    Trophy Points:
    38
    As far as I remember the server is running PHP 5! second of all, are you having any more problems, that we can help you out with?!?
     
  13. CascadesAdmin

    CascadesAdmin New Member

    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    i am checking now.
    Edit:
    another one:

    Line 50:

    PHP:
    mysql_close()); 
    Whole SQL code

    PHP:
    $query "INSERT INTO users (name, email, username, password) 
    VALUES('
    $name', '$email', '$username', '$password')"
    mysql_query($query) or die(mysql_error()) 
    mysql_close()); 
     
    Last edited: Jul 11, 2007
  14. Zenax

    Zenax Active Member

    Messages:
    1,377
    Likes Received:
    4
    Trophy Points:
    38
    your missing a ; at the end of the mysql_error line.
     
  15. CascadesAdmin

    CascadesAdmin New Member

    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    that doesnt solve line 50 the mysql_close());
     
    Last edited: Jul 11, 2007
  16. Micro

    Micro Retired staff <i> (11-12-2008)</I>

    Messages:
    1,301
    Likes Received:
    0
    Trophy Points:
    36
    Yeah, read thru that line char by char and see if you notice anything :p

    Hint: extra ) at the end...
     
  17. Chris Z

    Chris Z Active Member

    Messages:
    5,603
    Likes Received:
    0
    Trophy Points:
    36
    hah, yup, just about to tell you that ;)
    it should be:
    PHP:
    mysql_close();
    not:
    PHP:
    mysql_close());
     
  18. Zenax

    Zenax Active Member

    Messages:
    1,377
    Likes Received:
    4
    Trophy Points:
    38
    ahh, I did not notice that, lol.

    so any more problems you need our help with?
     
  19. CascadesAdmin

    CascadesAdmin New Member

    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    yeah,


    lines 54, 55, and 56:

    PHP:
    $yoursite ‘fanclub.cascades.exofire.net/
    $webmaster ‘Cascades Admin';
    $youremail = ‘noreply@cascades.exofire.net’; 
    when I take the "=" out I get this.

    lines 58, 59, 60, and 61:

    PHP:
    //------------------------
    //Send Mail TO User
    //------------------------
    $subject 'You have successfully registered at $yoursite...';
    and when I take the "=" out of that line I get this:

     
  20. Zenax

    Zenax Active Member

    Messages:
    1,377
    Likes Received:
    4
    Trophy Points:
    38
    Those errors are being caused by something before it, that is not properly closed. I am thinking it has something to do with lines 54 through to 56.

    I am not entirely sure you need the # at the beginning of the script, as that causes it to comment the rest out.

    So this being your original script:
    PHP:
    $yoursite ‘fanclub.cascades.exofire.net/
    $webmaster ‘Cascades Admin';
    $youremail = ‘noreply@cascades.exofire.net’;  

    //------------------------
    //Send Mail TO User
    //------------------------
    $subject = '
    You have successfully registered at $yoursite...'; 
    is read like this:

    PHP:
    $yoursite =
    $webmaster =
    $youremail =

    $subject 'You have successfully registered at $yoursite...';
    Your script should look like this:

    PHP:
    $yoursite 'fanclub.cascades.exofire.net/';
    $webmaster 'Cascades Admin';
    $youremail 'noreply@cascades.exofire.net';

    $subject 'You have successfully registered at '$yoursite .'...';
    Try that out and see if it works. I could be wrong however.
     

Share This Page