SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Location
    St. Francisville, LA USA
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP form submission not working.

    Hi ya'll. I am trying to work through Kevin's book on PHP and Mysql database websites version 3. The script I am trying to get to work should add the id, name and email to my database and then redirect the user to a new page personalized for the name entered in the form. The redirect personalization part of the script works just fine. It is on the landing page as such:
    <?php
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];

    echo ("<p class='signup'>Thanks for registering with us, $firstname $lastname!</p>");
    ?>

    The problem script is on the form page and is this:
    <?php
    if (isset($_POST['signup'])) :
    $dbcnx = @mysql_connect('localhost', 'root', 'print01');
    if (!$dbcnx) {
    exit ('<p>Unable to connect to ' .
    'database server at this time.</p>');
    }
    if (!@mysql_select_db('papa')) {
    exit ('<p>Unable to locate the form_data' .
    'database at this time.</p>');
    }
    $id = $_POST['id'];
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $email = $_POST['email'];
    $sql = "INSERT INTO form_data SET
    id = '$id',
    firstname = '$firstname',
    lastname = '$lastname',
    email = '$email'";
    ?>
    <?php endif; ?>

    The form is laid out to redirect the user to another page with personalization for the name entered in the form.

    The form is this:
    <div id="login">
    <form action="indexsignup.php" method="post" name="signup">
    <div><label for="firstname">First Name<input name="firstname" type= "text" class="formtext" size="40" /></label></div>
    <div><label for="lastname">Last Name<input type="text" name="lastname" class="formtext" size="40" /></label></div>
    <div><label for="email">Email<input type="text" name="email" class="formtext" size="40" /></label></div>
    <div><input type="submit" name="signupbtn" id="signupbtn" value="Sign Me Up!" /></div>
    </form>
    </div>

    Could you point me in the right direction? I am really new at this and I am not sure which page should have which script(although the personalized part does work). Thanks in advance. You guys are the best.

  2. #2
    SitePoint Addict
    Join Date
    Nov 2008
    Location
    Peterborough, Ontario, Canada
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is the form on indexsignup.php?

    If it is try changing

    isset($_POST['signup'])

    to:

    isset($_POST['signupbtn'])


    When does the script redirect to the personalized page?
    The best way to answer is to tell me the file names of the scripts
    Have I helped you? You could help me.
    Like my business on facebook!
    Text message polls with real-time, live results.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Location
    St. Francisville, LA USA
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Jeff thanks for the reply. I have two pages one is the indexsignup.html which has the form and currently the script to add the data to the database. The working script is on indexsignup.php which simply personalizes that page for the user. Should the script to add the data be on the indexsignup.php before the personalization script or after or will it work on the html page if I change the "if (isset($_POST['signup'])) :" to 'signupbtn'? I will try these two changes to see if I can get it working. Thanks much for the help. Bob

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Location
    St. Francisville, LA USA
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey ya'll just wanted to let you know I got this to work. Many thanks Jeff for helping point me in the right direction.


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
  •