What's wrong with my PHP code?

  • Thread starter Thread starter Chris88M20
  • Start date Start date
C

Chris88M20

Guest
I'm working on a homework assignment, adding data to a MySQL database with an HTML form and php code. I have the database, table, username and password all setup right. For some reason, my form won't post data to the table. Can anyone see a problem with my code?

<?php
$hostname = "localhost";
$db_user = "manager";
$db_password = "password";
$database = "cougarinn";
$db_table = "make_res";
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
?>
<html>
<head>
<title>Test Form</title>
</head>
<body>
<?php
if (isset($_REQUEST['Submit'])) {

$sql = "INSERT INTO
$db_table(firstName,lastName,emailAddress,phoneNumber,streetAddress,
city,state,zipCode,smoking,roomSize) values
('".mysql_real_escape_string(stripslashes($_REQUEST['firstName']))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['lastName']))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['emailAddress']))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['phoneNumber']))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['streetAddress']))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['city']))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['state']))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['zipCode']))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['smoking']))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['roomSize']))."')";

if($result = mysql_query($sql ,$db)) {
} else {
echo "ERROR: ".mysql_error();
}
} else {
?>
<form method="post" action="">
First Name<input type="text" maxlength="25" size="20" name="firstName">
Last Name<input type="text" maxlength="25" size="20" name="lastName">
e-mail Address<input type="text" maxlength="40" size="30" name="emailAddress">
Phone Number<input type="text" maxlength="10" size="12" name="phoneNumber">
Street Address<textarea name="streetAddress" rows="2" cols="35"></textarea>
City<input type="text" maxlength="30" size="25" name="city">
State<input type="text" maxlength="2" size="4" name="state" >
ZIP-code<input type="text" maxlength="5" size="7" name="zipCode"></td>
Smoking Room<input type="text" maxlength="3" size="5" name="smoking">
Room Size<input type="text" maxlength="10" name="roomSize" size="20">
<input type="submit" name="submit" value="Submit">
</form>
<?php
}
?>

</body>
</html>

sorry if the code is a bit messy.
 
Back
Top