SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot skipdawg95's Avatar
    Join Date
    Oct 2004
    Location
    Strasburg, VA
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Registration Form Problems

    I'm starting to get a hold of this php thing; however, it is coming at a cost. I'm losing my mind!!! I've been having a hell of a time trying to get this registration page set up and I've been having very little luck. Every time I move a step forward, I end up hitting a wall and then moving back about 10 steps. AAAHHHHH!!!!!

    Here's what I got! I'm using Dreamweaver 2004 MX and I'm finding that it's not updated with Imporved Mysql, so my queries where not working unless I inputed the text of the sql statement into the query itself. My last problem, as of this evening, is with the bolded text. I keep getting the following error:

    Parse error: syntax error, unexpected T_LOGICAL_AND in C:\Program Files\Apache Group\Apache2\htdocs\Bloodletting\PHP Docs\registration.php on line 13

    <?php require_once ('./connection.php'); ?>
    <?php
    //This statement will check to see if all required fields are completed. If not, upon submit, the page will refresh itself!
    if ((!$_POST[userName]) || (!$_POST[password1]) || (!$_POST[password2]) || (!$_POST[firstName]) || (!$_POST[lastName]) || (!$_POST[email])) {
    header("Location: ../Registration.htm");
    exit;
    }

    /*This following code will determine if the selected username is already in use. If it is, an error message will be given and the user will be required to choose another one. */
    if ($user = mysqli_query($conn, "SELECT * FROM userInfo WHERE userName = '$_POST[userName]'") or die ("Error: Mysql query failed!")) {
    $number = mysqli_num_rows($user);
    }
    if ($number == 0) AND ($_POST[password1] === $_POST[passsword2]) {
    mysqli_query("INSERT INTO userInfo (userName, password, firstName, lastName, age, emailAddress) VALUES ('$_POST[userName]', '$_POST[password2]', '$_POST[firstName]', '$_POST[lastName]', '$_POST[age]', '$_POST[emailAddress]')" or die ("Error writing to the database!");

    } else {
    print "The user name you have seleceted is already in use. Please select a different user name.";
    }
    if ($_POST[male] == true) {
    mysqli_query("INSERT INTO userInfo (gender) VALUES ('Male')";
    } else if ($_POST[female] == true) {
    mysqli_query("INSERT INTO userInfo (gender) VALUES ('Female')";
    }

    I tried using && inplace of AND, but I got the same results. Any suggestions? Also, if you have any suggestions on how I can improve the code, I'm all ears! My books are helpful, but not on the problems I keep coming accross.

  2. #2
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do not know--
    it looks good to me.

  3. #3
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WAIT--
    typos.

    You mean $_POST[password2] and == not ===.

  4. #4
    SitePoint Evangelist nick0161's Avatar
    Join Date
    Oct 2004
    Location
    australia
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    shouldn't that and statement be like this

    PHP Code:
    if (($number == 0) && ($_POST[password1] == $_POST[passsword2])) { 
    and if that doesn't work replace && with AND, i just think the whole if condition should be in brackets, i could be wrong but give it a shot

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi bud,
    on your code, the only thing I would change is..
    PHP Code:
    if($_POST['password1'] != $_POST['password2']) {
    print 
    "The passwords don't match.";
    }

    /*This following code will determine if the selected username is already in use. If it is, an error message will be given and the user will be required to choose another one. */ 
    $user mysqli_query($conn"SELECT * FROM userInfo WHERE userName = '$_POST[userName]'") or die ("Error: Mysql query failed!"mysql_error()); 
    $number mysqli_num_rows($user);

    if (
    $number 0) {
    print 
    "The user name you have selected is already in use. Please select a different user name.";
    } else {
    mysqli_query("INSERT INTO userInfo (userName, password, firstName, lastName, age, emailAddress) VALUES ('$_POST[userName]', '$_POST[password2]', '$_POST[firstName]', '$_POST[lastName]', '$_POST[age]', '$_POST[emailAddress]')" or die ("Error writing to the database!"mysql_error());


    if (
    $_POST[male] == true) {
    mysqli_query("INSERT INTO userInfo (gender) VALUES ('Male')";
    } else if (
    $_POST[female] == true) {
    mysqli_query("INSERT INTO userInfo (gender) VALUES ('Female')";

    Use mysql_error() incase things don't work!

    Try it and see what happens!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Zealot skipdawg95's Avatar
    Join Date
    Oct 2004
    Location
    Strasburg, VA
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys! I go the problem worked out. Now I just have to figure out how to make errors appear on the original registration page instead of in a new page. Any suggestions?

  7. #7
    SitePoint Zealot skipdawg95's Avatar
    Join Date
    Oct 2004
    Location
    Strasburg, VA
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually guys, I have no clue where to start on how to set up my web page to show errors on the page when information is missing or incorrect. Can someone guide me in the right direction? I could really use it!

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    dublin, Ireland
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    normally you will submit the page to itself so that
    if the values you submit are correct you can insert and display a message and then forward them to the page
    or
    if there's something wrong, you display the form with error messages displayed in the correct places


    // register.php

    if ( isset($_POST[username] )
    {
    // do some mysql with this variable

    header("location:register2.php"); // data is in database, onto step 2

    }
    else // somethings wrong, ask the user for the info again
    {
    echo "Please enter a user name.";
    echo "<form action="register.php" method="POST">;
    echo "<input type="text" name="username">
    echo "</form>
    }


    something like that, HTH

  9. #9
    SitePoint Zealot skipdawg95's Avatar
    Join Date
    Oct 2004
    Location
    Strasburg, VA
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I tried what you suggested and I've come up with a couple problems. I can get the errors to show up on the page, but not where I want them to show up. They appear at the top of the page. When this happens my banner gets removed from the return page. I've included the html code for my registration page and the php for the validation that's performed.

    Here's the html:

    HTML Code:
    <!-- saved from url=(0022)http://internet.e-mail -->
    <html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Language" content="en-us">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>Bloodletting</title>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_reloadPage(init) {  //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);
    //-->
    </script>
    <style type="text/css">
    <!--
    body {
    	background-color: #8A021A;
    }
    -->
    </style></head>
    
    <body>
    
    <p>
     
    </p>
    <table width="983" border="0" align="center">
      <tr>
        <td width="1315"><p align="center"><img border="0" src="Library/Banner%201.png" width="600" height="90"></p>
          <p>You can register yourself to become a member of the new online RPG, Bloodletting, by filling out and submitting the following form. Only registered users are allowed to enter the main site. This is a free forum-based RPG, so why not register to see what it's all about! Choose a username and password to access the site. After you have successfully registered, you will be able to access the character creation page where you will answer a series of questions to create your character. </p>
        <p>After you are successfully registered, you will receive a confirmation e-mail with a link to the Bloodletting login page. You must reply to this e-mail by clicking the link provided within the email in order to complete your registration. If confirmatin is not received within 24 hours, your information will be removed and you will have to create a new login. If you do not receive a confirmation email you can contact the <a href="mailto:docvoit@aol.com; mtr9525@verizon.net">support crew</a> for help! </p></td>
      </tr>
      <tr>
        <td><p align="center">&nbsp;</p>
          <hr>
          <form action="PHP Docs/registration.php" method="POST">
            <h2>Registration Form </h2>
            <table width="553">
              <tr>
                <td width="142" height="33"><div align="right"><strong>* User Name: </strong></div></td>
                <td colspan="2"><input name="userName" type="text" id="User Name" size="26" maxlength="20">
                </td>
                <td width="228"><em>(No more than 20 charaters)</em> </td>
              </tr>
              <tr>
                <td height="33"><div align="right"><strong>* Password:</strong></div></td>
                <td colspan="2"><input name="password1" type="password" size="26" maxlength="12">
                </td>
                <td><em>(Between 6-12 mixed characters)</em> </td>
              </tr>
              <tr>
                <td height="33"><div align="right"><strong><em>Confirm Password: </em></strong></div></td>
                <td colspan="2"><input name="password2" type="password" size="26" maxlength="12">
                </td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td height="33"><div align="right"><strong>* First Name:</strong></div></td>
                <td colspan="3"><input name="firstName" type="text" size="26" maxlength="25">
                </td>
              </tr>
              <tr>
                <td height="33"><div align="right"><strong>* Last Name: </strong></div></td>
                <td colspan="3"><input name="lastName" type="text" size="26" maxlength="20">
                </td>
              </tr>
              <tr>
                <td height="33"><div align="right"><strong>Age:</strong></div></td>
                <td colspan="3"><input name="age" type="text" size="10" maxlength="2"></td>
              </tr>
              <tr>
                <td height="33"><div align="right"><strong>Gender:</strong></div></td>
                <td width="78">              <p>
                    <label>
                    <input type="radio" name="RadioGroup1" value="male">
      </label>
                    <strong>Male</strong> </p>                </td>
                <td width="85"><input type="radio" name="RadioGroup1" value="female">
                  <strong>Female </strong></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td height="33"><div align="right"><strong>* Email Address: </strong></div></td>
                <td colspan="3"><input name="email" type="text" size="40" maxlength="50"></td>
              </tr>
              <tr>
                <td height="33" colspan="4"><strong>(*) Required Fields</strong></td>
              </tr>
              <tr>
                <td height="36"><div align="center">
                    <input type="submit" name="Submit" value="Register">
                </div></td>
                <td colspan="2"><div align="center">
                    <input type="reset" name="Submit2" value="Clear Form">
                </div></td>
                <td>&nbsp;</td>
              </tr>
            </table>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
        </form></td>
      </tr>
      <tr>
        <td><p align="center">&nbsp;</p>
          <hr>
          <h5> Copyright  2003 [Voit]. All rights reserved.<br>
      Revised:
        <!--webbot bot="TimeStamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->
        May 30, 2004
        <!--webbot bot="TimeStamp" endspan i-checksum="11029" -->
      .<br>
        </h5></td>
      </tr>
    </table>
    <p align="center">&nbsp;</p>
    </body>
    
    </html>

    Here's the PHP:
    PHP Code:
    <?php require_once ('./connection.php'); ?>
    <?php
    if (isset($_POST['Submit'])) {
    //This statement will check to see if all required fields are completed.  If not, upon submit, the page will refresh itself!
    if ((!$_POST[userName]) || (!$_POST[password1]) || (!$_POST[password2]) || (!$_POST[firstName]) || (!$_POST[lastName]) || (!$_POST[email])) {
        print 
    "Please fill in the required fields and resubmit the form!<br>";
        include(
    "../Registration.htm");
        exit;
        }
        
    //This following code will validate that the passwords match.  If they don't, an error will be displayed and the script will be terminated.  
    if ($_POST[password1] != $_POST[password2]) {
        print 
    "The passwords don't match.<br>";
        include(
    "../Registration.htm");
        exit;
        }

    /* Next step is to determine if the inputed username is already in use.  If it is, an error will be displayed and the script will terminate.  The email address will also be checked to see if it is listed in the database.  If it is, an error will be displayed and the scipt will terminate. */
    if ($user mysqli_query($conn"SELECT * FROM userInfo WHERE userName = '$_POST[userName]'") or die ("Error:  Mysql query failed!")) {
        
    $number mysqli_num_rows($user);
        }
    if (
    $number != 0) {
        print 
    "The user name you have seleceted is already in use.  Please select a different user name.";
        include(
    "../Registration.htm");
        exit;
        }
    if (
    $user2 mysqli_query($conn"SELECT * FROM  userInfo WHERE emailAddress = '$_POST[email]'") or die ("Error:  Mysqli query failed!")) {
        
    $number2 mysqli_num_rows($user2);
        }
    if (
    $number2 != 0) {
        print 
    "That email address is already listed in the database.  Please contact the support crew for further assistance!<br>";
        include(
    "../Registration.htm");
        exit;
        }
    if ((
    $number == 0) && ($number2 == 0)) {
        
    mysqli_query($conn"INSERT INTO userInfo (userName, password, firstName, lastName, age, emailAddress) VALUES ('$_POST[userName]', '$_POST[password2]', '$_POST[firstName]', '$_POST[lastName]', '$_POST[age]', '$_POST[email]')") or die ("Error writing to the database!");
        } 
            
    if (
    $_POST[RadioGroup1] == "male") {
        
    mysqli_query($conn"UPDATE userInfo SET gender = 'Male' WHERE userName = '$_POST[userName]'");
        } else if (
    $_POST[RadioGroup1] == "female") {
                
    mysqli_query($conn"UPDATE userInfo SET gender = 'Female' WHERE userName = '$_POST[userName]'");
                }
    }
    ?>
    Any Ideas!?

  10. #10
    SitePoint Zealot skipdawg95's Avatar
    Join Date
    Oct 2004
    Location
    Strasburg, VA
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never mind guys! I finally figured it out. Works great now! Thanks for all your help!


Bookmarks

Posting Permissions

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