我提交联系表格

时间:2017-04-01 11:03:34

标签: php

我已经联系了......一旦提交了相同的详细信息,我们就会将用户重定向到“谢谢你”页面;但是在提交时......用户没有被定向到“谢谢你页面”。你能找出错误吗?我真的很感激..非常感谢你!

<?php 
include("company_profile/lib/data.config.php"); 
$btnsubmit  =isset($_POST['btnsubmit'])?$_POST['btnsubmit']:'';
if(isset($_POST['btnsubmit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$cource = $_POST['cource'];
$message = $_POST['message'];
$created_date = date('Y-m-d');
$time = date('H:i:s');
$q="Insert INTO enquiry_form SET name='$name',email='$email',
contact='$phone',message='$message',cource='$cource',
created_date='$created_date',etime='$time'";

    $r = mysqli_query($conn,$q);

   if($r) 
    {
    //echo "Thankyou for Inquery";
    header("location:thanks.php");
    //echo "<script>alert('Message Send')</script>";



  }else
  {
    echo "there was a problem";
  }

  }

  ?>

4 个答案:

答案 0 :(得分:1)

你试试下面的SQL

      INSERT INTO enquiry_form(name,email,contact,message,courece,created_date,etime) VALUES (?,?,?,?,?,?,?)
if($stmt=$conn->prepare($q){
$stmt->bind_param('/dependent your datatype',$name,$email,$contact,...);
$stmt->execute();
echo "<script>
window.location.href='thank.php';
alert('Thank you');
</script>"

}

答案 1 :(得分:0)

尝试检查最后插入的ID,然后它会将您重定向到目标脚本。请发布您的HTML表单。也许是错误。这必须100%工作。

contact-page.php中的Php代码

<?php 

include("company_profile/lib/data.config.php");

if(isset($_POST['btnsubmit']))
{
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $email = mysqli_real_escape_string($conn, $_POST['email']);
    $phone = mysqli_real_escape_string($conn, $_POST['phone']);
    $cource = mysqli_real_escape_string($conn, $_POST['cource']);
    $message = mysqli_real_escape_string($conn, $_POST['message']);
    $created_date = date('Y-m-d');
    $time = date('H:i:s');

    $q = "INSERT INTO enquiry_form ( name, email, contact, message, cource, created_date, etime ) VALUES ( '$name', '$email', '$phone', '$message', '$cource', '$created_date', '$time' )";

    $r = mysqli_query($conn, $q);

    // if is returned last inserted id
    if(mysqli_insert_id($conn)) 
    {
        header("location:thanks.php");
    }
    else
    {
        echo "there was a problem";
    }

}

?>

联系人-page.php中的Html表单

<form  action="contact-page.php" method="POST">
    <label>Name</label><br>
    <input type="text" name="name" required /><br>
    <label>Subject</label><br>
    <input type="text" name="cource" required /><br>
    <label>Email</label><br>
    <input type="text" name="email" pattern="[^ @]*@[^ @]*" required /><br>
    <label>Phone</label><br>
    <input type="tel" name="phone" maxlength="10" pattern="[0-9]{10,11}" pattern="[0-9]{10}" required /><br>
    <label>Message</label><br>
    <textarea cols="46" rows="3" name="message" required></textarea><br>
    <input class="button" type="submit" value="Sumbit" name="btnsubmit" />
</form>

答案 2 :(得分:0)

再次使用pdo并过滤您的请求

<?php
include("company_profile/lib/data.config.php"); 
$btnsubmit  =isset($_POST['btnsubmit'])?$_POST['btnsubmit']:'';
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
if(isset($_POST['btnsubmit']))
{
$name = $_POST['name']; // filter string  number encode ......
$email = $_POST['email']; // filter string number encode ......
$phone = $_POST['phone']; // filter string number encode ......
$cource = $_POST['cource']; // filter string number encode ......
$message = $_POST['message']; // filter string number encode ......
$created_date = date('Y-m-d'); // filter string number encode ......
// we are in 2017 use pdo
$pdo = $con->prepare("Insert INTO enquiry_form SET name= :name,email=:email,contact=:phone,message=:message,cource=:cource,created_date= now()");
$pdo->execute(array('name' => $name,'email' => $email, 'phone' => $phone, 'message' => $message, 'cource' => $cource ));
   if($pdo) 
    {
    //echo "Thankyou for Inquery";
    header("location:thanks.php");
    //echo "<script>alert('Message Send')</script>";



  }else
  {
    echo "there was a problem";
  }

  }
}
 ?>`

答案 3 :(得分:-1)

在php中你需要写ob_start();在代码的开头,让您的标头缓冲。您可以在ob_start:What's the use of ob_start() in php?的重要性上看到此前发布的帖子,或查看php手册:http://php.net/manual/en/function.ob-start.php

如果你没有代码的snippit,你的标题将无效。