以下表格是从用户那里收集以下信息: - 名称 - 电子邮件地址 - 共享项目的类型 - 物品数量 - 共享项目清单
问题是共享的电子邮件地址和项目列表没有存储到数据库中。所有其他字段都正确存储。
<form name="form1" method="post" action="feedback.php" class="pure-form">
<fieldset class="pure-group">
<input type="text" class="pure-input-1-2" placeholder="Sharetype" value="Nativity" id="SharingSharetype" name="SharingSharetype" readonly>
<input type="text" class="pure-input-1-2" placeholder="Name" id="SharingName" name="SharingName">
<input type="email" class="pure-input-1-2" placeholder="Email" id="SharingEmail name="SharingEmail">
</fieldset><br>
<fieldset class="pure-group">
<input type="text" pattern="\d*" class="pure-input-1-2" placeholder="Number of Items" id="SharingNum" name="SharingNum">
<textarea class="pure-input-1-2" placeholder="List items you want to share" id="SharingShared_items name="SharingShared_Items"></textarea>
</fieldset>
<button type="submit" class="pure-button pure-input-1-2 pure-button-primary">Submit</button>
</form>
&#13;
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="db"; // Database name
$tbl_name="table"; // 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 = mysql_escape_string($_POST['SharingName']);
$Email = mysql_escape_string($_POST['SharingEmail']);
$Sharetype = mysql_escape_string($_POST['SharingSharetype']);
$Shared_Items = mysql_escape_string($_POST['SharingItems']);
$Num = $_POST[SharingNum];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(Name, Email, Sharetype, Shareditems, Num, ShareDate)VALUES('$Name', '$Email', '$Sharetype', '$Shared_Items', '$Num', Now())";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
mysql_close();
header( 'Location: http://www.googe.com/' );
exit;
}
else {
mysql_close();
header( 'Location: http://www.google.com/' );
exit;
}
?>
<?php
// close connection
mysql_close();
?>
&#13;
答案 0 :(得分:0)
替换
id="SharingEmail name="SharingEmail"
与
id="SharingEmail" name="SharingEmail"
和
id="SharingShared_items name="SharingShared_Items"
与
id="SharingShared_items" name="SharingShared_Items"