dtip91401 2013-04-03 19:42
浏览 23
已采纳

PHP返回同一页面,调用header()函数

Hi I'm making a php page that return to itself when submitting form, but there's a case inside the php that when it's true a header("Location: url") function should be performed.

Is it possible to do so?

        <form action="" method="post">
      <input type="text" name="username" value="" />
        <?php
 if (isset($_POST['submitted'])) {

$username = $_POST['username'];

        $qryS="SELECT * FROM student WHERE ID='$username';";
        $resultS=mysql_query($qryS);
            if($resultS){
            if(mysql_num_rows($resultS)>=1) {

            header("location: studentprofile.php");
            }}
                else {

            echo"<p><small> There was an error</p>";

            }   
}

         ?>
      <input type="submit" name="submitted" value="Submit" /></p>

    </form>
  • 写回答

5条回答 默认 最新

  • donglian1523 2013-04-03 19:44
    关注

    You can not send any headers after you already sent data (HTML). If you move the if-clauses and header() calls to before you output anything - there's no problems.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 深度学习残差模块模型
  • ¥20 两个不同Subnet的点对点连接
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)