2017-04-01 51 views
-2

我已經聯繫了......本應該將用戶重定向到「謝謝」頁面,一旦提交了相同的詳細信息;然而,在提交..用戶沒有被引導到「謝謝你」頁面。你能找出錯誤嗎?我會非常感激..非常感謝你!當我提交我的聯繫表時

<?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"; 
    } 

    } 

    ?> 
+0

查詢syntaxe pb ...並看看SQL注入... https://phpdelusions.net/sql_injection – Incognito

+0

有一件事'$ btnsubmit = isset($ _ POST ['btnsubmit'])?$ _ POST [ 'btnSubmit按鈕']: '';如果(isset($ _ POST ['btnsubmit']))'你不應該這樣做,第二;哪裏的html表單呢? –

+0

你對SQL注入攻擊很有信心,如果你還沒有,你會被黑客攻擊**。不要將任意數據直接連接到查詢中。使用PDO或類似的綁定參數。 – Brad

回答

1

你試試下面

 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>" 

SQL; }

+0

我的代碼工作正常值成功保存在數據庫,但頁面不重定向 –

+0

您可以嘗試'' – Akashii

+0

'我等一下,我編輯評論,並幫助您避免SQL注入 – Akashii

0

嘗試此操作檢查最後插入的ID,然後它會將您重定向到您的目標腳本。並請張貼您的HTML表單。也許在那裏也是錯誤的。這必須工作100%。

PHP代碼中接觸page.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"; 
    } 

} 

?> 

HTML表單中接觸page.php文件再次

<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> 
+0

@arifkhan試試這個代碼,你會看到它的工作 – Mario

+0

ys馬里奧我的權利,我將不得不mantion行動=「contact-page.php」然後每件事情工作很好,謝謝很多馬里奧和saeed誰保存我的工作 –

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"; 
    } 

    } 
} 
?>` 
+0

看到我想告訴你我的代碼條件,我有一個三個文件的第一個文件名是contact-us.php,第二個文件是contact-page .php,第三個文件名是thanks.php,並且在contact-us.php中包含contact-page.php文件,我確實分享了我的contact-page.php文件.and一個爲我已經給予的行動=「thanks.php」在contact-page.php –

-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

如果您沒有該代碼的瑕疵,那麼您的標題將無法使用。

+0

可以編輯相同的代碼,無論你說我請在我的辦公室 –

+0

我沒有。嘗試添加ob_start();在<?php之後,看看它是否有幫助。我應該提到,這將幫助您重定向問題,但不一定是您的數據庫問題。 –

+0

它不工作 –