Form Info Won't Post To Database

G

Guest

Guest
I am using an html form to try and post to a MySQL database. When I submit the form, it says the information has been entered, but when I view the database contents, the new info isn't there. I am really clueless about all of this but I'm learning. I am including the code of both files below.

First, the form:
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Add a Property Listing</title>
</head>

<body>

<form method="POST" action="addlisting.php3" name="Add Listing">
<p>City <input type="text" name="city" size="20" tabindex="1"></p>
<p>Street <input type="text" name="street" size="20" tabindex="2"></p>
<p>Listing Price <input type="text" name="price" size="20" tabindex="3"></p>
<p>Bedrooms <input type="text" name="bedrooms" size="2" tabindex="4">
Baths <input type="text" name="baths" size="2" tabindex="5"> SQ Feet <input type="text" name="sqfeet" size="5" tabindex="6"></p>
<p>Directions:</p>
<p> <textarea rows="2" name="directions" cols="58" tabindex="7"></textarea></p>
<p>Description:</p>
<p><textarea rows="2" name="description" cols="59" tabindex="8"></textarea></p>
<p>Picture Name <input type="text" name="picture" size="20" tabindex="9"></p>
<p> </p>
<p><input type="submit" value="Submit" name="Add Listing"><input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>

Now, the .php3:

<?php



$db = mysql_connect("localhost", "username", "password");
mysql_select_db("scbankforeclosures_com",$db);




$sql="INSERT INTO LISTINGS (city, street, price, bedrooms, baths, sqfeet, directions, description, picture) VALUES ($city, $street, $price, $bedrooms, $baths, $sqfeet, $directions, $description, $picture);";

$result = mysql_query($sql);

echo "Thank you! Information entered.\n";



?>

Obviouusly, I use the correct username and password in the actual file.
Any ideas?

Thanks! :?:
 
Firstly I'm gonna presume you've got the Global Variables turned off, so you'll need to refer to each variable as $_POST['city'] instead of just $city.

Also, try printing out the $sql variable to see if the query is being made up and structured correctly.
 
:lol: Well, you try to insert strings into a table without qoutes?! :D

Code:
$sql="INSERT INTO LISTINGS (city, street, price, bedrooms, baths, sqfeet, directions, description, picture) VALUES ('$city', '$street', '$price', '$bedrooms', '$baths', '$sqfeet', '$directions', '$description', '$picture');";

BUT! You must replace all escape characters(for instanse, same qoutes) in all fields, that may have the string data type.

P.S. RTFM

------------------------
With best regards,
Serge Bulanov
AlarIT Web developer,
www.AlarIT.com [/code]
 
Back
Top