从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>";
?>

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.

to debug a case like this, comment out the first half of your program (if (0) { ... }), set the variables by hand, and see if the mysql code inesrts the variables.

Then do the reverse, comment out the mysql part, and see if the variables are getting set from the form.

You also need to escape values passed to mysql to prevent sql injection attacks