doulang6013 2014-12-03 02:30
浏览 98
已采纳

从HTML表单到MySQL的数据插入不完整

Only the email and telephone data fields are being populated in the DB.

firstName, lastName, and changeRequest are not being populated.
I am getting the message "Form Submitted".

<html>
<body bgcolor="99ccff">
<head>
<title>Change Request</title>
</head>

<h1>Submitting Change Request</h1>

<p>Change Request</p>


<form name="htmlform" method="post" action="html_form_send.php">
<table width="450px">
</tr>
<tr>
 <td valign="top">
  <label for="first_name">First Name *</label>
 </td>
 <td valign="top">
  <input  type="text" name="firstName" maxlength="50" size="30">
 </td>
</tr>

<tr>
 <td valign="top"">
  <label for="last_name">Last Name *</label>
 </td>
 <td valign="top">
  <input  type="text" name="lastName" maxlength="50" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="email">Email Address *</label>
 </td>
 <td valign="top">
  <input  type="text" name="email" maxlength="80" size="30">
 </td>

</tr>
<tr>
 <td valign="top">
  <label for="telephone">Telephone Number</label>
 </td>
 <td valign="top">
  <input  type="text" name="telephone" maxlength="30" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="changeRequest">Change Request *</label>
 </td>
 <td valign="top">
  <textarea  name="changeRequest" maxlength="1000" cols="25" rows="6"></textarea>
 </td>

</tr>
<tr>
 <td colspan="2" style="text-align:center">
  <input type="submit" value="Submit">   
 </td>
</tr>
</table>
</form>

<



</body>
</html>

html_form_send.php

    <?php

define('DB_NAME', 'mytestdb');
define('DB_USER', 'root');
define('DB_PASS', '7vMUgtEU8NnU');
define('DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);

if (!$link) {
    dir('There was a problem when trying to connect to the host. Please contact Tech Support. Error: ' . mysql_error());    
}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$link) {
    dir('There was a problem when trying to connect to the database. Please contact Tech Support. Error: ' . mysql_error());    
}

$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$changeRequest = $_POST['changeRequest'];

$sql = "INSERT INTO changeRequest (firstName, lastName, email, telephone, changeRequest) VALUES ('$firstName', '$lastName', '$email', '$telephone', '$changeRequest')";

if (!mysql_query($sql)) {
    die('Error: ' . mysql_error()); 
}
echo "<p>Form Submitted</br>";
?>
  • 写回答

2条回答 默认 最新

  • duandianwen1723 2014-12-03 02:38
    关注

    There is a </tr> attribute under the table attribute, I think the first thing is to make this right.

    There is a < after the </form> too. Please delete it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器