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