SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question how to make the submit button go to and refresh results page?

    CLICK HERE TO SEE THE SITE IN QUESTION

    When you click the sign up button I want the browser to be directed to the results page. Please can someone show me how to do this?

    This is the sign up page php:

    PHP Code:
    <?php
    if (isset($_POST['submit'])) {

         if (!
    get_magic_quotes_gpc()) {
             
    $id addslashes($id);
            
    $name addslashes($name);
             
    $email addslashes($email);
              
    $course addslashes($course);
               
    $question addslashes($question);
        }

    $dbh=mysql_connect ("localhost""username""password");
            
    mysql_select_db ("username");


       
    $sql "INSERT INTO unrealtournament VALUES ('$id','$name','$email','$course','$question')";

        
    $result mysql_query($sql) or print("Can't insert into table emaillist.<br />" $sql "<br />" mysql_error());

        if (
    $result != false) {
            print 
    "Your entry has successfully been entered into the database.";
        }

        
    mysql_close();
    }
    ?>

    <form  method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <table align="center" border="1" cellspacing="0" cellpadding="3">
    <tr><td>Username:</td><td>
    <input type="text" name="name" maxlength="40">

    </td></tr>
    <tr>
      <td>E-Mail:</td>
      <td>
    <input type="text" name="email" maxlength="100">
    </td></tr>
    <tr>
      <td>Course:</td>
      <td>
    <input type="text" name="course" maxlength="150">
    </td></tr>
    <tr>
      <td>Would you like: </td>
      <td>
    <select name="question">
    <option value="Death Match" selected="selected">Death Match</option>
    <option value="Capture the Flag">Capture the Flag</option>
    <option value="Both">Both</option>
    </select>
    </td></tr>
    <tr><td colspan="2" align="right">
    <input type="submit" name="submit" value="Sign Up">
    </td></tr>
    </table>
    </form>
    Last edited by shtoom; Dec 31, 2006 at 01:01.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
        if ($result != false) {
            
    header('Location: http://example.com/results.php');
            exit;
        } 
    Off Topic:


    your code relies on the register_globals setting. this setting has been defaulted to off for years now, and if you want your code to be portable you should not rely on this setting. using variables created by register_globals can also have security implications.

    use the superglobals instead eg
    $_POST['id'] instead of $id

    http://www.php.net/register_globals

  3. #3
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, as long as nothing has been outputted to the browser, use

    PHP Code:
    header('location: http://www.jamesgardner.lincoln.ac.uk/unrealtournament/results.php'); 

  4. #4
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    clamcrusher

    I added your code and when I sign up it takes me to index.php and I see this

    Can't insert into table emaillist.
    INSERT INTO emaillist (email) VALUES ('dtw@a')
    Table 'jamesgar_jamesgar.emaillist' doesn't exist
    Warning: Cannot modify header information - headers already sent by (output started at /home2/jamesgar/public_html/unrealtournament/index.php:6) in /home2/jamesgar/public_html/unrealtournament/index.php on line 93


    and are you saying everywhere it says $id I replace it with $_POST['id']

    Looks like something has been outputted to the browser

    I added what you told me and I got this error
    Warning: Cannot modify header information - headers already sent by (output started at /home2/jamesgar/public_html/unrealtournament/index.php:6) in /home2/jamesgar/public_html/unrealtournament/index.php on line 145

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you sent some output on line 6. output is text, html, or whitespace characters. you cannot send output before sending headers.

    you can either use an html meta refresh, javascript redirect, or turn on output buffering by calling ob_start(); on the first line of your script.

  6. #6
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just added ob_start(); and I get the same error

    To use superglobals are you saying to replace $id with $_POST['id'] ? if so does it apply for all of them $name $_POST['name'] ect.. ?

    Heres what the php now looks like:
    PHP Code:

    <?php

    ob_start
    ();

    if (isset(
    $_POST['submit'])) {

         if (!
    get_magic_quotes_gpc()) {
             
    $id addslashes($id);
            
    $name addslashes($name);
             
    $email addslashes($email);
              
    $course addslashes($course);
               
    $question addslashes($question);
        }

    $dbh=mysql_connect ("localhost""username""password");
            
    mysql_select_db ("username");


       
    $sql "INSERT INTO unrealtournament VALUES ('$id','$name','$email','$course','$question')";

        
    $result mysql_query($sql) or print("Can't insert into table emaillist.<br />" $sql "<br />" mysql_error());

    if (
    $result != false) {
            
    header('Location: http://www.jamesgardner.lincoln.ac.uk/unrealtournament/results.php');
            exit;
        } 

        
    mysql_close();
    }
    ?>

    <div id="main">
    Its time to get it on..
    </div>

    <form  method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <table align="center" border="1" cellspacing="0" cellpadding="3">
    <tr><td>Username:</td><td>
    <input type="text" name="name" maxlength="40">

    </td></tr>
    <tr>
      <td>E-Mail:</td>
      <td>
    <input type="text" name="email" maxlength="100">
    </td></tr>
    <tr>
      <td>Course:</td>
      <td>
    <input type="text" name="course" maxlength="150">
    </td></tr>
    <tr>
      <td>Would you like: </td>
      <td>
    <select name="question">
    <option value="Death Match" selected="selected">Death Match</option>
    <option value="Capture the Flag">Capture the Flag</option>
    <option value="Both">Both</option>
    </select>
    </td></tr>
    <tr><td colspan="2" align="right">
    <input type="submit" name="submit" value="Sign Up">
    </td></tr>
    </table>
    </form><br />


    </div>
    </body>
    </html>
    <?php

    ob_end_flush
    ();

    ?>

  7. #7
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    put it at the beggining of the file, on line 1.

    you will also obviously need to fix your database error.

  8. #8
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow thanks it works now!

    Whats the error in the database?

    and to use superglobals are you saying to replace $id with $_POST['id'] ? if so does it apply for all of them $name $_POST['name'] ect.. ?

  9. #9
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •