goto function php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gwolff2005
    New Member
    • Apr 2009
    • 3

    goto function php

    I have a test page. If the user presses "go on", it is supposed to go to the page passiontest2.ph p. But for what ever reason it does not work. Any help would be appreciated :-)

    [code=text]<?php ini_set("displa y_errors","2");
    ERROR_REPORTING (E_ALL);?>
    <?php require_once('C onnections/Login.php'); ?>
    <?php
    session_start() ;
    ?>
    <?php
    //You will need to update all the below variables
    $mysqlhost = "localhost" ;
    $mysqluser = "guntmar";
    $mysqlpass = "je20sa05";
    $mysqldb = "guntmar";
    $mysqltable = "users";
    $username = "username";
    $currentpo = "resultspo" ;
    $currentmo = "resultsmo" ;
    $id = $_SESSION['id'];
    $url = "http://www.guntmarwolf f.com/passiontest2.ph p" ;

    // End Variables

    mysql_connect($ mysqlhost, $mysqluser, $mysqlpass);
    mysql_select_db ($mysqldb);

    $query = "SELECT * FROM " . $mysqltable . " WHERE username='" . $username . "'";

    $result = mysql_query($qu ery) or die("There was a mysql error");
    while($row = mysql_fetch_arr ay($result)){
    $currentpo = $row['resultspo'];
    $currentmo = $row['resultsmo'];
    }
    function showForm () {
    echo <<<SHOWFORM
    <form id="form1" name="form1" method="post" action="">
    <table width="699" border="0" align="center" cellspacing="5" class="style1">
    <tr>
    <td colspan="3"><di v align="center"> <span class="style4"> Your Passion Test</span></div></td>
    </tr>
    <tr>
    <td width="24">&nbs p;</td>
    <td width="429">&nb sp;</td>
    <td width="220"><di v align="right">S aturday, 03/28/09</div></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><div align="right">$ _SESSION[MM_firstname]</div></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><div align="right"></div></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>1</td>
    <td><strong>I like talking to people. </strong><br />
    </b></td>
    <td><div align="left">
    <input name="po1" type="radio" value="0" />
    0
    <input name="po1" type="radio" value="1" />
    1
    <input name="po1" type="radio" value="2" />
    2
    <input name="po1" type="radio" value="3" />
    3
    <input name="po1" type="radio" value="4" />
    4
    <input name="po1" type="radio" value="5" />
    5</div></td>
    </tr>
    <tr>
    <td>2</td>
    <td>It is important for me what other people think. </td>
    <td><p>
    <label></label>
    <label></label>
    <input name="mo2" type="radio" value="0" />
    0
    <input name="mo2" type="radio" value="1" />
    1
    <input name="mo2" type="radio" value="2" />
    2
    <input name="mo2" type="radio" value="3" />
    3
    <input name="mo2" type="radio" value="4" />
    4
    <input name="mo2" type="radio" value="5" />
    5<br />
    <br />
    </p></td>
    </tr>
    <tr>
    <td>3</td>
    <td class="style1"> My level of excitement is high right now. </td>
    <td><p>
    <label></label>
    <input name="mo3" type="radio" value="0" />
    0
    <input name="mo3" type="radio" value="1" />
    1
    <input name="mo3" type="radio" value="2" />
    2
    <input name="mo3" type="radio" value="3" />
    3
    <input name="mo3" type="radio" value="4" />
    4
    <input name="mo3" type="radio" value="5" />
    5<br />
    </p></td>
    </tr>
    <tr>
    <td>4</td>
    <td>I like solving mathematical tasks. </td>
    <td><input name="po4" type="radio" value="0" />
    0
    <input name="po4" type="radio" value="1" />
    1
    <input name="po4" type="radio" value="2" />
    2
    <input name="po4" type="radio" value="3" />
    3
    <input name="po4" type="radio" value="4" />
    4
    <input name="po4" type="radio" value="5" />
    5</td>
    </tr>
    </table>
    <p align="center">
    <input name="Submit" type="submit" class="style1" value="go on" />
    </p>
    </form>
    SHOWFORM;
    }//Close showForm()
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Your Passion Test</title>
    <style type="text/css">
    <!--
    .style1 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 11px;
    font-weight: bold;
    color: #000033;
    }
    .style3 {font-family: Verdana, Arial, Helvetica, sans-serif}
    .style4 {
    font-size: 20px;
    color: #996600;
    }
    -->
    </style>
    </head>

    <body>
    <?php
    if (!isset($_POST['Submit'])) {
    showForm();
    } else {
    $pagepo = ($_POST['po1'] + $_POST['po4']);
    $pagemo = ($_POST['mo2'] + $_POST['mo3']);

    $newpo = ($currentpo + $pagepo);
    $newmo = ($currentmo + $pagemo);


    $query = "Update ".$mysqltab le." SET resultspo = resultspo + '".$newpo."' , resultsmo = resultsmo + '".$newmo."' WHERE id = '".$_SESSION['id']."'";

    mysql_query($qu ery) or die("There was a mysql error<br />Query: {$query}<br />Error Returned: " . mysql_error());
    }
    ?>
    </body>
    </html>[/code]
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Your form has no action set. There is no redirect anywhere. How do you supposed it is going to change pages?

    Comment

    • gwolff2005
      New Member
      • Apr 2009
      • 3

      #3
      goto page

      @marcus. Yeah I set already the header but it did not work. So instead of confusing everyone I deleted it and hope that somecan help me in getting the right code at the right place...

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        You should have stated that. Anyway, please post the unedited code.

        Comment

        • gwolff2005
          New Member
          • Apr 2009
          • 3

          #5
          Code:
          header('Location: passiontest2.php');
          which I put at 4th line above ending. If I put it higher the actual page is immediately directed without showing the content. If I put it at the 4th line above ending I get the message:
          Warning: Cannot modify header information - headers already sent by

          Comment

          Working...