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
  1. #1
    New Coder
    Join Date
    Nov 2006
    Location
    Malvern, PA
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Registration script help

    I have some code I am trying to customize for my site.
    Submitting the form leads me to a blank page. Inspecting the source code for this page shows me that it is only the header.html section included in the script. Even with all errors being reported I can't get any hints about what's happening.

    I been staring at this all day and hoping a new pair of eyes might help.

    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    ini_set('display_errors','On') ;

    $page_title 'Register';
    include (
    'header.html');

    echo 
    '<div id=\"form\">' ;

    // Check if the form has been submitted:
    if (isset($_POST['submitted'])) {

        require_once (
    'mysqli_connect.php'); // Connect to the db. $dbc is set here
    //  $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );    

            
    $errors = array(); // Initialize an error array.
        
        // Check for a first name:
        
    if (empty($_POST['fname'])) {
        
             
    $errors[] = 'You forgot to enter your first name.';
        } else {
            
    $fn mysqli_real_escape_string($dbctrim($_POST['fname']));
        }
        
        
    // Check for a last name:
        
    if (empty($_POST['lname'])) {

            
    $errors[] = 'You forgot to enter your last name.';
        } else {
            
    $ln mysqli_real_escape_string($dbctrim($_POST['lname']));
        }
        
        
    // Check for an email address:
        
    if (empty($_POST['email'])) {

            
    $errors[] = 'You forgot to enter your email address.';
        } else {
            
    $e mysqli_real_escape_string($dbctrim($_POST['email']));
        }
        
        
    // Check for a password and match against the confirmed password:
        
    if (!empty($_POST['pass'])) {
            if (
    $_POST['pass'] != $_POST['passconf']) {

                
    $errors[] = 'Your password did not match the confirmed password.' ;
            } else {
                
    $p mysqli_real_escape_string($dbctrim($_POST['pass']));
            }
        } else {

            
    $errors[] = 'You forgot to enter your password.';
        }
        
        if (empty(
    $errors)) { // If everything's OK.
        
            // Register the user in the database...
            
            // Make the query:
            
    $q "INSERT INTO contacts VALUES ('$e', password('$p'), '$fn', '$ln', '$d', '$ev', '$ce', '$contactid', NOW() )";
            
    $result = @mysqli_query ($dbc$q); // Run the query.
            
    if ($result) { // If it ran OK.
            
                // Print a message:
                
    echo '<h1>Thank you!</h1>
            <p>You are now registered. In Chapter 11 you will actually be able to log in!</p><p><br /></p>'
    ;    
            
            } else { 
    // If it did not run OK.
                
                // Public message:
                
    echo '<h1>System Error</h1>
                <p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'

                
                
    // Debugging message:
                
    echo '<p>' mysqli_error($dbc) . '<br /><br />Query: ' $q '</p>';
                            
            } 
    // End of if ($result) IF.
            
            
    mysqli_close($dbc); // Close the database connection.

            // Include the footer and quit the script:
            
    include ('footer.html'); 
            exit();
            
        } else { 
    // Report the errors.
        
            
    echo '<h1>Error!</h1>
            <p class="error">The following error(s) occurred:<br />'
    ;
            foreach (
    $errors as $msg) { // Print each error.
                
    echo " - $msg<br />\n";
            }
            echo 
    '</p><p>Please try again.</p><p><br /></p>';
            
        } 
    // End of if (empty($errors)) IF.
        
        
    mysqli_close($dbc); // Close the database connection.

    // End of the main Submit conditional.
    ?>



    <p class="header">Travel Team and High School Registration</p>
    <p>We have upgraded our registration system. Please create an account.<br>
    * denotes a required field</p>
    <form action="register.php" method="post">
        <p>First Name: <input type="text" name="fname" size="15" maxlength="20" value="<?php if (isset($_POST['fname'])) echo $_POST['fname']; ?>" /></p>
        <p>Last Name: <input type="text" name="lname" size="15" maxlength="40" value="<?php if (isset($_POST['lname'])) echo $_POST['lname']; ?>" /></p>
        <p>Email Address: <input type="text" name="email" size="20" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"  /> </p>
        <p>Password: <input type="password" name="pass" size="10" maxlength="20" /></p>
        <p>Confirm Password: <input type="password" name="passconf" size="10" maxlength="20" /></p>
        <p><input type="submit" name="submit" value="Register" /></p>
        <input type="hidden" name="submitted" value="TRUE" />
    </form>

    </div>

    <?php
    include ('footer.html');
    ?>
    Last edited by dmilani; 08-14-2008 at 04:05 PM.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    PHP Code:
    <?php
    // Check if the form has been submitted:
    if (isset($_POST['submitted'])) {
    /.....
    // End of the main Submit conditional.
    ?>
        <p><input type="submit" name="submit" value="Register" /></p>
        <input type="hidden" name="submitted" value="TRUE" />
    submitted is hidden, submit is submit with value Register
    in fact the hidden field is useless

    regards

  • #3
    New Coder
    Join Date
    Nov 2006
    Location
    Malvern, PA
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I thought that whole thing looked funny, but I am not sure how to fix it.
    Should the last two inputs be swapped?
    Suggestions?

    Thanks for looking!

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by dmilani View Post
    I thought that whole thing looked funny, but I am not sure how to fix it.
    Should the last two inputs be swapped?
    Suggestions?

    Thanks for looking!
    replace in $_POST, submitted with submit.

    Edit: and you can remove the line with
    Code:
    <input type="hidden" name="submitted" ...
    best regards

  • #5
    New Coder
    Join Date
    Nov 2006
    Location
    Malvern, PA
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts
    So I made the suggested changes, but I am still getting the same result. Any other ideas?

  • #6
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    try deleting */

    2 second glance at code for the win
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #7
    New Coder
    Join Date
    Nov 2006
    Location
    Malvern, PA
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hey hinch,

    Thanks for joining the discussion. Alas I removed that already with no success.

    Bueler, bueler. . .

  • #8
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    had a better look now still can't see anything really wrong with it you could try using mysql_pconnect instead of mysqli would require a few other changes but that's really my desperate attempt to guess whats going wrong. Sorry I can't help more

    2nd thoughts try deleteing this too
    error_reporting(E_ALL);
    ini_set('display_errors','On') ;

    also is password($p) a proper function for mysqli ? typically i I use md5() around the inserted password
    Last edited by hinch; 08-14-2008 at 04:15 PM.
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #9
    New Coder
    Join Date
    Nov 2006
    Location
    Malvern, PA
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Update: It seems that the mysqli_ functions are not installed on my host.
    Also, I realized I was suppressing the errors with the @'s before my queries.

    Now, I am having trouble converting the query from mysqli_query to mysql_query.

    SOLVED THIS: I am getting an error that there is No Database selected.

    BTW: What is the difference btwn mysqli_xxxx and mysql_xxxx ?
    Last edited by dmilani; 08-14-2008 at 05:59 PM.

  • #10
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    thats a good question I don't know the answer for apart from I've never been able to get mysqli to work and it usually seems people only use it with php4 though i'm sure someone will correct me on that

    you could try using mysql_fetch_row and mysql_fetch_array instead of mysql_fetch_assoc there's limitations with assoc which are resolved by using row for singles and array for table returns.

    http://uk2.php.net/mysql_fetch_assoc
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com


  •  

    Posting Permissions

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