2013-07-24 18 views
0

我有以下代碼,用於檢查用戶是否通過表單註冊了電子郵件地址,然後發送PIN提醒。如何在提交表單後添加echo語句

//check if email already taken 
    $emailRes = mysqli_query($conn,"SELECT * FROM users WHERE user_email = '{$_POST['srEmail']}'"); 

    if(mysqli_num_rows($emailRes) != 0) {//if email found in table 
     $emailRec = mysqli_fetch_assoc($emailRes); 
     ?> 
     Email already registered, would you like a PIN reminder? 
     <form method="POST" action=""> 
     <input type="submit" name="srSend" value="Click here to get pin reminder" /> 
     <input type="hidden" name="srEmail" value="<?php echo $emailRec['user_email']?>" /> 
     </form> 
     <?php 
     exit; 

    } 

目前在提交完成時返回空白頁;我將如何添加「成功」。信息?

+4

警告:''mysqli_query($ conn,「SELECT * FROM users WHERE user_email ='{$ _POST ['srEmail']}'」);'適合SQL注入攻擊。 – Ryan

+0

你的問題不是很清楚......何時提交完成?提交以獲取引腳提醒?或者是什麼?嘗試通過在您的頁面上發佈更多代碼來使問題變得易於理解 – oliverdejohnson

回答

1

表單的action屬性指定將POST請求與輸入數據一起發送的位置。現在它是空白的,這不是你想要的。你需要將這些數據發送到另一個腳本,然後可以顯示你想要的任何內容。

例子:

屬性:

action="after_form.php" 

after_form.php

<?php 

//do form processing 

echo "Nice, you sent the form data here!"; 

你也可以派人到同一個PHP腳本,然後指示爲POST語句發送不同的輸出由Amal下面。

+1

並非總是如此。可以將表單發送給自己。 –

+0

當然,這是真的,但是這是什麼讓你認爲這種情況。在任何情況下它都是不好的形式:http://stackoverflow.com/questions/1131781/is-it-a-good-practice-to-use-an-empty-url-for-a-html-forms-action-屬性-a – thatidiotguy

+0

我同意Amal,我認爲它是這裏的情況,因爲表單在if語句中,並且處理邏輯引用相同的srEmail字段 – oliverdejohnson

0

只需刪除關閉PHP標籤查詢後補充一點:

echo "Email already registered, would you like a PIN reminder?"; 

,然後添加結束PHP的標記。

如果電子郵件已存在,將顯示一條消息。