【问题标题】:Form posting other page getting error with php表单发布其他页面出现php错误
【发布时间】:2017-07-29 09:21:57
【问题描述】:

表单发布到其他页面(重定向)和数据库存储并获得结果的问题我是 php 初学者

这里是代码

include 'include/header.php';
include 'include/connect.php';
if(isset($_SESSION['id']) && $_SESSION['id']!='')

    $reslt = mysqli_query($connection,"SELECT * FROM `queries` WHERE   id='".$_SESSION['id']."'");
    $row1= mysqli_fetch_array($reslt);


    if(isset($_POST['submitquery'])){
        $title= $_POST['title'];
        $contact = $_POST['queries'];

        header("Location:pnf.php");
    }else{
        $msg='<span style="color:red;text-align:center;font-size:15px">Sorry you miss some</span>';   
    }

html

<form method="post" class="postquations">
    <label><b><class="p">Set your quaition title</b></label>
    <br>

    <input type="text" placeholder="Title"id="title" name="title"  minlength="25" required=""autocomplete="off"  oninvalid="true"><br>
    <label><b>ask your quation</b></label>
    <br>

    <textarea class="textinput" rows="10" minlength="100" id="queries"name="queries" style="overflow:hidden" placeholder="Comment Here.." required></textarea>
    <input type="submit"id="submit" class="butn"value="POST" name="submitquery">
</form>

pnf.php

<div class="title" > <?php echo $row['title'];?></div>
<div class="quation"> <?php echo $row['queries'];?></div>

请帮助我并解释为什么我们没有得到结果提前谢谢

【问题讨论】:

  • 你对pnf.php有什么期待
  • @MasivuyeCokile 结果页面
  • 我没有看到 session_start() 包含文件之一吗?
  • 我也没有看到$row
  • 您的&lt;form method="post" class="postquations"&gt; 没有action="nameOfPHPScript.php 属性

标签: php forms mysqli


【解决方案1】:

header("Location:pnf.php"); 导致 php 在响应中设置位置标头, 用户浏览器将读取此标头并向pnf.php 执行新的GET 请求。

由于这是一个新的 GET 请求,$_POST 在运行 pnf.php 时不会被填充。

另外,整个 sql 代码显得多余。

整个事情可能需要重新考虑,但最简单的选择是将表单 action 属性更改为 pnf.php 并在那里处理数据

【讨论】:

  • 如果您有具体问题,我很乐意回答,但我不会尝试“提供已解决的代码”,因为我对您的项目知之甚少,而且您也不会学到太多东西如果我这样做了。
猜你喜欢
  • 2014-01-18
  • 2012-09-04
  • 1970-01-01
  • 2011-11-03
  • 2018-04-18
  • 2019-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多