-3
我想用JavaScript來驗證我的聯繫方式,但我不知道驗證碼,在哪裏包括驗證使用javascript在PHP
我想驗證重定向到thank_you.php頁
之前應該發生PLZ幫我...
HTML
<fieldset>
<?php include("formcode.php"); ?>
</fieldset>
formcode.php
<form method='post' action="database.php">
NAME: <input type='text' name='name' id='name' />
Email: <input type='text' name='email' id='email' />
Contact: <input type='text' name='contact' id='contact' />
Tour:
<select id="tour" name="tour" >
<option value="">--Select Tours--</option>
<option value="Tour1">Tour1</option>
<option value="Tour2">Tour2</option>
</select><br/>
Location:
<select id="location" name="location" >
<option value="">--Select Your Location--</option>
<option value="Loc1">Loc1</option>
<option value="Loc2">Loc2</option>
</select><br/>
Comment:<br />
<textarea name='comment' id='comment' /></textarea><br />
<input type='submit' value='Submit' />
</form>
database.php中
<?php
if($_POST)
{
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_name", $con);
$users_name = $_POST['name'];
$users_email = $_POST['email'];
$users_contact = $_POST['contact'];
$users_tour = $_POST['tour'];
$users_location = $_POST['location'];
$users_comment = $_POST['comment'];
$users_name = mysql_real_escape_string($users_name);
$users_email = mysql_real_escape_string($users_email);
$users_contact = mysql_real_escape_string($users_contact);
$users_tour = mysql_real_escape_string($users_tour);
$users_location = mysql_real_escape_string($users_location);
$users_comment = mysql_real_escape_string($users_comment);
$query = "
INSERT INTO `db_name`.`dbtable` (`id`, `name`, `email`, `contact`, `tour`, `location`, `comment`, `timestamp`, `articleid`)
VALUES (Null, '$users_name', '$users_email', '$users_contact', '$users_tour', '$users_location', '$users_comment', CURRENT_TIMESTAMP);";
mysql_query($query);
$url = 'thank_you.php';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
mysql_close($con);
include("mail.php");
}
?>
嘗試wrtie一些驗證代碼,這樣我們就可以,如果幫你你不能讓它工作 – gbestard
http://www.w3schools.com/js/js_form_validation.asp –
你也必須在PHP中驗證你的表單,而不僅僅依賴於JS驗證。 –