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 10 of 10

Thread: New problem

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    New problem

    OK,
    New problem. I got the page to load and my form appears. I fill out the form and press submit. The page loads again and the form comes up again blank!? I am once again stumped.
    Here is my code:

    PHP Code:
    <?php include('header.php'); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>SD Computerz - Register</title>
    <style type="text/css">
    <!--
    .style1 {color: #000000}
    body,td,th {
     color: #FFFFFF;
    }
    body {
     background-color: #000000;
    }
    -->
    </style>

    </head>
    <body>
    <span class="style1"></span>
    <center><h1>SD Computerz</h1></center><br />
    <?php include('menu.html'?>
    <hr />
    <center>
    <?php
    $user
    ="user";
    $password="pass";
    $database="database";
    $host="host";
    mysql_connect($host,$user,$password)or die("Could not connect to database");
    mysql_select_db($database) or die( "Unable to select database");

    $username=$_POST['username'];
    $pass=$_POST['pass'];
    $pass2=$_POST['confirm_pass'];
    $email=$_POST['email'];
    if(
    $_SESSION['logged_in'] == 1)
    { echo(
    'You are already logged in. Please <a href="http://www.sdcomutrez.com/logout.php">log out</a> or go to the <a href="http://www.sdcomputerz.com">homepage</a>');
    }
    else
    {
    if(isset(
    $_POST['submit']))
    {
    if(!
    $username)
    {
    die(
    'Alert: Userame field left blank!');
    }
    $q2 mysql_query("SELECT * FROM `members` WHERE `username` = '".$username."'");
    $q3 mysql_fetch_object($q2);
    if(
    $q3->username == $username)
    {
    die(
    'Alert: The username $username is already stored in our database. Please <a href="http://www.sdcomputerz.com/contact.php">contanct an administrator</a> if you feel there is a mistake');
    }
    if(!
    $pass)
    {
    die(
    'Alert: Password field was left blank.');
    }
    if(!
    $pass2)
    {
    die(
    'Alert: Verify Password field was left blank.');
    }
    if(
    $pass != $pass2)
    {
    die(
    'Alert: Password fields did not match.');
    }
    if(!
    $email)
    {
    die(
    'Alert: Email field was left blank.');
    }
    $query"INSERT INTO `members` (`id`, `username`, `password`, `email`) VALUES ('', '$username', '$pass', 'email'), ('', '', '', '')";
    mysql_query($query);
    echo(
    'Thank you for signing up. You may now <a href="http://www.sdcomputerz.com/login.php">login</a>.');
    mysql_close();
    }
    else
    {
    ?>
    <table>
    <form name="register" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    <tr>
    <td>
    <p>*Indicates required field.</p>
    </td>
    </tr>
    <tr>
    <td>
    <p>Username*</p>
    </td>
    <td>
    <input type="text" name="username" />
    </td>
    </tr>
    <tr>
    <td>
    <p>Password*</p>
    </td>
    <td>
    <input type="password" name="pass" />
    </td>
    </tr>
    <tr>
    <td>
    <p>Confirm Password*</p>
    </td>
    <td>
    <input type="password" name="pass2" />
    </td>
    </tr>
    <tr>
    <td>
    <p>Email*</p>
    </td>
    <td>
    <input type="text" name="email" />
    </td>
    </tr>
    <tr>
    <td>
    </td>
    <td>
    <input type="submit" value="Submit" />
    </td>
    </tr>
    </form>
    </table>
    <?php
    }
    }
    ?>
    </center>
    </body>
    </html>
    Thanks again for you help and patience.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    i did notice one thing
    PHP Code:
    die('Alert: The username $username is already stored in our database. Please <a href="http://www.sdcomputerz.com/contact.php">contanct an administrator</a> if you feel there is a mistake'); 
    shouldn't that be
    PHP Code:
    die('Alert: The username' $username ' is already stored in our database. Please <a href="http://www.sdcomputerz.com/contact.php">contanct an administrator</a> if you feel there is a mistake'); 

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,526
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    I think I know what it is ...

    See these lines ... Add a bracket (in blue) ... remove the bracket (in red)

    else
    {
    if(isset($_POST['submit']))
    {
    if(!$username)
    {
    die('Alert: Userame field left blank!');
    }
    $q2 = mysql_query("SELECT * FROM `members` WHERE `username` = '".$username."'");
    $q3 = mysql_fetch_object($q2);
    if($q3->username == $username)
    {
    die('Alert: The username $username is already stored in our database. Please <a href="http://www.sdcomputerz.com/contact.php">contanct an administrator</a> if you feel there is a mistake');
    }
    if(!$pass)
    {
    die('Alert: Password field was left blank.');
    }
    if(!$pass2)
    {
    die('Alert: Verify Password field was left blank.');
    }
    if($pass != $pass2)
    {
    die('Alert: Password fields did not match.');
    }
    if(!$email)
    {
    die('Alert: Email field was left blank.');
    }
    $query= "INSERT INTO `members` (`id`, `username`, `password`, `email`) VALUES ('', '$username', '$pass', 'email'), ('', '', '', '')";
    mysql_query($query);
    echo('Thank you for signing up. You may now <a href="http://www.sdcomputerz.com/login.php">login</a>.');
    mysql_close();
    }
    }
    else
    {
    ?>
    <table>
    <form name="register" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    <tr>
    <td>
    <p>*Indicates required field.</p>
    </td>
    </tr>
    <tr>
    <td>
    <p>Username*</p>
    </td>
    <td>
    <input type="text" name="username" />
    </td>
    </tr>
    <tr>
    <td>
    <p>Password*</p>
    </td>
    <td>
    <input type="password" name="pass" />
    </td>
    </tr>
    <tr>
    <td>
    <p>Confirm Password*</p>
    </td>
    <td>
    <input type="password" name="pass2" />
    </td>
    </tr>
    <tr>
    <td>
    <p>Email*</p>
    </td>
    <td>
    <input type="text" name="email" />
    </td>
    </tr>
    <tr>
    <td>
    </td>
    <td>
    <input type="submit" value="Submit" />
    </td>
    </tr>
    </form>
    </table>
    <?php
    }
    }
    ?>
    </center>
    </body>
    </html>
    Last edited by mlseim; 03-27-2007 at 02:26 PM.

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Nah, I think the problem is that there isn't enough brackets.

    If you format the code properly, you can spot it

    PHP Code:
    <?php include('header.php'); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>SD Computerz - Register</title>
    <style type="text/css">
    <!--
    .style1 {
        color: #000000

    }
    body,td,th {
        color: #FFFFFF;
    }
    body {
        background-color: #000000;
    }
    -->
    </style>

    </head>
    <body>
    <span class="style1"></span>
    <center><h1>SD Computerz</h1></center><br />
    <?php include('menu.html'?>
    <hr />
    <center>
    <?php
    $user
    ="user";
    $password="pass";
    $database="database";
    $host="host";
    mysql_connect($host,$user,$password)or die("Could not connect to database");
    mysql_select_db($database) or die( "Unable to select database");

    $username=$_POST['username'];
    $pass=$_POST['pass'];
    $pass2=$_POST['confirm_pass'];
    $email=$_POST['email'];
    if(
    $_SESSION['logged_in'] == 1){ 
        echo(
    'You are already logged in. Please <a href="http://www.sdcomutrez.com/logout.php">log out</a> or go to the <a href="http://www.sdcomputerz.com">homepage</a>');
    }else{
        if(isset(
    $_POST['submit'])){
            if(!
    $username){
                die(
    'Alert: Userame field left blank!');
            }
            
    $q2 mysql_query("SELECT * FROM `members` WHERE `username` = '".$username."'");
            
    $q3 mysql_fetch_object($q2);
            if(
    $q3->username == $username){
                die(
    'Alert: The username $username is already stored in our database. Please <a href="http://www.sdcomputerz.com/contact.php">contanct an administrator</a> if you feel there is a mistake');
            }
            if(!
    $pass){
                die(
    'Alert: Password field was left blank.');
            }
            if(!
    $pass2){
                die(
    'Alert: Verify Password field was left blank.');
            }
            if(
    $pass != $pass2){
                die(
    'Alert: Password fields did not match.');
            }
            if(!
    $email){
                die(
    'Alert: Email field was left blank.');
            }
                
    $query"INSERT INTO `members` (`id`, `username`, `password`, `email`) VALUES ('', '$username', '$pass', 'email'), ('', '', '', '')";
                
    mysql_query($query);
                echo(
    'Thank you for signing up. You may now <a href="http://www.sdcomputerz.com/login.php">login</a>.');
                
    mysql_close();
            }else{
    ?>
                <table>
                    <form name="register" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
                        <tr>
                            <td><p>*Indicates required field.</p></td>
                        </tr>
                        <tr>
                            <td><p>Username*</p></td>
                            <td><input type="text" name="username" /></td>
                        </tr>
                        <tr>
                            <td><p>Password*</p></td>
                            <td><input type="password" name="pass" /></td>
                        </tr>
                        <tr>
                            <td><p>Confirm Password*</p></td>
                            <td><input type="password" name="pass2" /></td>
                        </tr>
                        <tr>
                            <td><p>Email*</p></td>
                            <td><input type="text" name="email" /></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td><input type="submit" value="Submit" /></td>
                        </tr>
                    </form>
                </table>
    <?php
            
    }
        }
    }
    ?>
    </center>
    </body>
    </html>

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,526
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    Nightfire ...

    you might be right ... I didn't try formatting it first,
    but I know there's a problem with the brackets.

    I tried counting them with my finger (the non-techie way)


    For those newbies to PHP ... see how important it is to
    properly format your code? It really helps with troubleshooting.

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Yeah I tried looking down the screen and counting lol Had some time so ended up sorting it properly

  • #7
    Registered User
    Join Date
    Apr 2006
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well I appreciate the advice and all but... my form still won't work.
    In order to see my problem, why don't you visit my form at this page.

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Give your submit button a name.

    <input type="submit" value="Submit" name="submit" />

  • #9
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Form comes up blank eh? How bout you put in the values?

    Code:
    <input type="text" name="email" value="<?php echo stripslashes($_POST['email']); ?>" />

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,526
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    There's some really basic troubleshooting (programming 101)
    things you can do ...

    Use some echo statements to figure it out.

    Insert them in various spots ....

    echo "test1";

    echo "test2";

    see where your program is not executing.

    comment-out various parts ...
    To isolate sections.


  •  

    Posting Permissions

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