2
我正在一個傳呼網站上的php窗體上工作。我遇到了兩個問題。首先是表單在提交時跳轉到頁面的頂部。我已經嘗試了一些不同的事情來防止這種情況發生,但似乎沒有任何結果。第二個是表單會話保持啓動狀態,如果用戶點擊ctrl-r,導致我的數據庫空白重新提交。頁面跳轉在PHP表單提交
如果有人知道如何否定頁面跳轉提交我正在體驗那將是驚人的。
感謝,
<?php
if(isset($_POST['add']))
{
$dbhost = 'XXX';
$dbuser = 'XXX';
$dbpass = 'XXX';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn)
{
die('Could not connect: ' . mysql_error());
}
if(! get_magic_quotes_gpc())
{
$form_name = addslashes ($_POST['form_name']);
$form_email = addslashes ($_POST['form_email']);
$form_phone = addslashes ($_POST['form_phone']);
$form_linkedin = addslashes ($_POST['form_linkedin']);
$form_q1 = addslashes ($_POST['form_q1']);
$form_q2 = addslashes ($_POST['form_q2']);
$form_q3 = addslashes ($_POST['form_q3']);
$form_q4 = addslashes ($_POST['form_q4']);
$form_q5 = addslashes ($_POST['form_q5']);
}
else
{
$form_name = $_POST['form_name'];
$form_email = $_POST['form_email'];
$form_phone = $_POST['form_phone'];
$form_linkedin = $_POST['form_linkedin'];
$form_q1 = $_POST['form_q1'];
$form_q2 = $_POST['form_q2'];
$form_q3 = $_POST['form_q3'];
$form_q4 = $_POST['form_q4'];
$form_q5 = $_POST['form_q5'];
}
$sql = "INSERT INTO XXX".
"(form_name, form_email, form_phone, form_linkedin, form_q1, form_q2, form_q3, form_q4, form_q5) ".
"VALUES('$form_name','$form_email','$form_phone', '$form_linkedin', '$form_q1', '$form_q2', '$form_q3', '$form_q4', NOW())";
mysql_select_db('XXX');
$retval = mysql_query($sql, $conn);
if(! $retval)
{
die("<section id='thank_you'><h1>SOMETHING WENT WRONG</h1><p class='about_body_txt'>Click <a href='XXX'>here</a> to resubmit</p></section>");
}
echo("<section id='thank_you'><h1>THANK YOU</h1><p class='about_body_txt'>Selected participants will be notified by July 8, 2014. Click <a href='XXX'>here</a> to return to the main site.</p></section>");
mysql_close($conn);
}
else
{
?>
<form id="gfbm_form" class="theForm" role="form" autocomplete="off" method="POST">
<h2>APPLICATIONS DUE<br/>
<span class="medium_txt">THURSDAY, JULY 3RD AT 5PM, EST.</span></h2>
<div class="application">
<ul>
<li class="small_field">
<span><label class="label_field">Name</label></span>
<br/>
<input id="form_name" class="name input_field" type="text" name="form_name" />
</li>
<li class="small_field">
<span><label class="label_field">Email</label></span>
<br/>
<input id="form_email" class="email input_field" type="text" name="form_email" />
</li>
<li class="small_field_2">
<span><label class="label_field">Phone</label></span>
<br/>
<input id="form_phone" class="phone input_field" type="text" name="form_phone" />
</li>
<li class="small_field_2">
<span><label class="label_field">LinkedIn</label></span>
<br/>
<input id="form_linkedin" class="linkedin input_field" type="text" name="form_linkedin" />
</li>
<li class="essay_question">
<span><label class="label_field">QUESTION 1</label></span>
<br/>
<textarea id="form_q1" class="q1 input_field_big" type="text" name="form_q1"></textarea>
</li>
<li class="essay_question">
<span><label class="label_field">QUESTION 2</label></span>
<br/>
<textarea id="form_q2" class="q2 input_field_big" type="text" name="form_q2"></textarea>
</li>
<li class="essay_question">
<span><label class="label_field">QUESTION 3</label></span>
<br/>
<textarea id="form_q3" class="q3 input_field_big" type="text" name="form_q3"></textarea>
</li>
<li class="essay_question">
<span><label class="label_field">QUESTION 4</label></span>
<br/>
<textarea id="form_q4" class="q4 input_field_big" type="text" name="form_q4"></textarea>
</li>
</ul>
<input type="checkbox" required id="checkbox-2-1" class="regular-checkbox big-checkbox" />
<label class="check_text">
<p>YES, I'LL BE AVAILABLE FOR ALL OF THOSE DATES.</p>
</label>
<input type="checkbox" required id="checkbox-2-2" />
<label class="check_text">
<p>I have read and understand the terms and conditions.</p>
</label>
<input name="add" type="submit" class="submit btn btn-default" id='submit' value="APPLY">
</form>
你會聽到很多,不要使用貶低的MYSQL_語句。 – Locke
你見過這個問題嗎? http://stackoverflow.com/questions/20274683/how-to-stop-a-page-jumping-to-the-top-once-a-form-is-submitted或http://stackoverflow.com/questions/ 12715387/how-to-jump-to-anchor-on-submit-not-to-top-of-page –
@ rlb.usa我還沒有看到這個。我要關閉這個帖子了。謝謝! – unfollow