PHP - 表单提交后重定向到另一个网页

时间:2015-09-21 17:00:07

标签: php

我的代码在向MySQL数据库提交数据方面做得很好。提交后,我想转到另一页。我已阅读了有关此主题的许多帖子,一致的答案是使用header('Location: /directory/mypage.php');

我试图将此标题插入到我页面上的许多不同位置,但我无法将其工作。我确定我错过了一些小事,但我无法找到问题所在。我的代码如下。提前谢谢。

<html>   
<body>
  <?php

  session_start();
  $sessionid = session_id();

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

        $dbhost = 'localhost:3036';
        $dbuser = 'user';
        $dbpass = 'pass';
        $conn = mysql_connect($dbhost, $dbuser, $dbpass);

        if(! $conn )
        {
           die('Could not connect: ' . mysql_error());
        }

        if(! get_magic_quotes_gpc() )
        {
           $Gravity = addslashes ($_POST['Gravity']);
           $Time = addslashes ($_POST['BoilTime']);
        }
        else
        {
           $Gravity= $_POST['Gravity'];
           $Time = $_POST['BoilTime'];
        }

        $IBU = $_POST['IBU'];

                $sql = "INSERT INTO tblVariableTimeUtilzation ( Sessionid, Gravity, IBU, ml, Time, Utilization ) SELECT '$sessionid',tblIBUat60minBoil.Gravity, tblIBUat60minBoil.IBU, tblIBUat60minBoil.ml, tblUtilization.Time, tblUtilization.Utilization FROM tblIBUat60minBoil INNER JOIN tblUtilization ON tblIBUat60minBoil.Gravity = tblUtilization.Gravity GROUP BY tblIBUat60minBoil.Gravity, tblIBUat60minBoil.IBU, tblIBUat60minBoil.ml, tblUtilization.Time, tblUtilization.Utilization HAVING (((tblIBUat60minBoil.Gravity)=". $Gravity .") AND ((tblIBUat60minBoil.IBU)=". $IBU . ") AND ((tblUtilization.Time)='60'));";

                $sql2 = "INSERT INTO tblPull60MinUtilization ( Sessionid, Gravity, IBU, ml, Time, Utilization ) SELECT '$sessionid', tblIBUat60minBoil.Gravity, tblIBUat60minBoil.IBU, tblIBUat60minBoil.ml, tblUtilization.Time, tblUtilization.Utilization FROM tblIBUat60minBoil INNER JOIN tblUtilization ON tblIBUat60minBoil.Gravity = tblUtilization.Gravity GROUP BY tblIBUat60minBoil.Gravity, tblIBUat60minBoil.IBU, tblIBUat60minBoil.ml, tblUtilization.Time, tblUtilization.Utilization HAVING (((tblIBUat60minBoil.Gravity)=". $Gravity .") AND ((tblIBUat60minBoil.IBU)=". $IBU . ") AND ((tblUtilization.Time)='60'));";

       $sql3 = "SELECT Sessionid FROM tblPull60MinUtilization WHERE Sessionid='59a185f576f0d27ab5ae5825fe1463f3'";
 $result = mysql_query($sql3); 
 $myrow = mysql_fetch_array($result);


        mysql_select_db('ExtractCalculation');
        $retval = mysql_query( $sql, $conn );

        if(! $retval )
        {
           die('Could not enter data: ' . mysql_error());
        }

        $retval2 = mysql_query( $sql2, $conn );

        if(! $retval2 )
        {
          die('Could not enter data: ' . mysql_error());
        }

     echo "Entered data successfully";
        header('Location: http://www.cnn.com);
        mysql_close($conn);
     }
     else
     {
        ?>

           <form method="post" action="<?php $_PHP_SELF ?>">
              <table width="400" border="0" cellspacing="1" cellpadding="2">

                 <tr>
                    <td width="100">Gravity</td>
                    <td><input name="Gravity" type="text" id="Gravity"></td>
                 </tr>

                 <tr>
                    <td width="100">IBU</td>
                    <td><input name="IBU" type="text" id="IBU"></td>
                 </tr>

                 <tr>
                    <td width="100">Boil Time</td>
                    <td><input name="BoilTime" type="text" id="BoilTime"></td>
                 </tr>

                 <tr>
                    <td width="100"> </td>
                    <td> </td>
                 </tr>

                 <tr>
                    <td width="100"> </td>
                    <td>
                       <input name="add" type="submit" id="add" value="Calculate mls Needed">

                    </td>
                 </tr>



              </table>

           </form>

        <?php
     }

  ?>

</body>
</html>

0 个答案:

没有答案