我正在尝试在我的网站上设置一个表单,但它给了我一个错误,我确定我的代码是正确的,但它仍然无法正常工作。
我正在努力寻找问题,任何帮助将不胜感激。这是 php 脚本:
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="orders_mysql"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$name=$_POST["name"];
$lastname=$_POST["lastname"];
$address=$_POST["address"];
$address2=$_POST["address2"];
$city=$_POST["city"];
$state=$_POST["state"];
$zip=$_POST["zip"];
$country=$_POST["country"];
$phone=$_POST["phone"];
$bra_size=$_POST["bra_size"];
$bra_color=$_POST["bra_color"];
$cami_size=$_POST["cami_size"];
$cami_color=$_POST["cami_color"];
$email=$_POST["email"];
// Insert data into mysql
$sql="INSERT INTO orders_mysql(name, lastname, address, address2, city, state, zip, country, phone, bra_size, bra_color, cami_size, cami_color, email)VALUES('$name', '$lastname', '$address' '$address2', '$city', '$state', '$zip', '$country', '$phone', '$bra_size', '$bra_color', '$cami_size', '$cami_color', '$email')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='index.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
<?php
// close connection
mysql_close();
?>
这是 HTML:
<form action="insert_ac.php" id="order" method="post" >
<center><span class="products_title">Select Quantity, Size and Color</span>
<img id="product" src="/images/seamlesscami.jpg" alt="Seamless Cami">
<label for="selectList">Size</label>
<select id="selectList">
<option value="Option 1">Small</option>
<option value="Option 2">Medium</option>
<option value="Option 3">Large</option>
</select>
<ul>
<li>
<fieldset>
<legend id="title1" class="desc">
Select a Choice
</legend>
<div>
<span>
<input id="Field1_0" name="Field1" type="radio" class="field radio" checked="checked">
<label class="choice" for="Field1_0" style="background:beige; height:40px; width: 50px; float: left;"></label>
</span>
<span>
<input id="Field1_1" name="Field1" type="radio" class="field radio">
<label class="choice" for="Field1_1" style="background:black; height:40px; width: 50px; float: left;"></label>
</span>
</div>
</fieldset>
</li>
</ul>
</center>
</div>
<div class="one-third column form_pos">
<center><span class="products_title">Select Quantity, Size and Color</span>
<img id="product" src="/images/seamlesscontrolbrief.jpg" alt="Seamless Control Brief">
<label for="selectList">Size</label>
<select id="selectList">
<option value="Option 1">Small</option>
<option value="Option 2">Medium</option>
<option value="Option 3">Large</option>
</select>
<ul>
<li>
<fieldset>
<legend id="title2" class="desc">
Select a Choice
</legend>
<div>
<span>
<input id="Field1_3" name="Field2" type="radio" class="field radio" checked="checked">
<label class="choice" for="Field1_3" style="background:beige; height:40px; width: 50px; float: left;"></label>
</span>
<span>
<input id="Field1_4" name="Field2" type="radio" class="field radio">
<label class="choice" for="Field1_4" style="background:black; height:40px; width: 50px; float: left;"></label>
</span>
</div>
</fieldset>
</li>
</ul></center>
</div>
<div class="fifteen columns">
<p id="order">*Your free bonus offer will be automatically deducted at checkout with each BraWizard ordered. All you will be charged is 7.99 for additional processing and handling. New Jersey Residents add tax. 60 day gaurentee less S/H.</p>
</div>
<center>
<div class="fourteen columns" style="background: lightgrey; margin: 0 50% 0 7%;">
<div class="seven columns">
<center>
First name:* <input type="text" name="name" required>
Address 1:* <input type="text" name="address" required>
City:* <input type="text" name="city" required>
Zip Code:* <input type="text" name="zip" required>
Email Address:* <input type="text" name="email" required>
</center>
</div>
<div class="six columns">
<center>
Last name:* <input type="text" name="lastname" required>
Address 2:* <input type="text" name="address2" required>
State:* <input type="text" name="state" required>
Country:* <input type="text" name="country" required>
Phone Number:* <input type="text" name="phone" required>
</center>
</div>
</div>
</center>
<div class="sixteen columns">
<button type="submit" value="submit" name="Submit" style="margin-left:38%;"><img src="/images/order.jpg" alt="order"></button>
</form>
</div>
</div>
</div><!-- container -->
<!-- End Document
================================================== -->
</body>
</html>