dqpfl2508589 2015-09-19 03:02
浏览 48
已采纳

php表单不发布电子邮件和textarea数据

The form below is collecting the following information from users: - Name - Email Address - Type of item being shared - The number of items - List of items being shared

The problem is that the email address and list of items being shared are not getting stored to the database. All other fields are being stored properly.

<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>

<?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();
?>

</div>
  • 写回答

1条回答 默认 最新

  • dongwei7913 2015-09-19 03:06
    关注

    replace

    id="SharingEmail name="SharingEmail"
    

    with

    id="SharingEmail" name="SharingEmail"
    

    and

    id="SharingShared_items name="SharingShared_Items"
    

    with

    id="SharingShared_items" name="SharingShared_Items"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化