我创建了我的 html 页面和我的 php 脚本来将表单数据推送到 mySQL 数据库,但是当我单击提交时,我得到了这个错误。
警告:mysql_connect() [function.mysql-connect]:在“读取初始通信数据包”时丢失与 MySQL 服务器的连接,系统错误:111 in
这是我的脚本:
<?php
$host="custsql-ipg06.eigbox.net"; // Host name
$username="brawiz"; // Mysql username
$password="mffirm2013"; // Mysql password
$db_name="brawizard"; // 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 $tbl_name(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='insert.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
<?php
// close connection
mysql_close();
?>
<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>