Advertisement

09.25.2007 at 09:51AM PDT, ID: 22851521
[x]
Attachment Details

Using a PHP form to enter data into mysql database

Asked by baumli1 in PHP and Databases

Tags: data, enter, php, database, form

I'm trying to insert the results of a form into a mysql database.  

Here's my condensed form:
-------------------------------------------------
<body>
<form method="post" action="script.php">
  <p><strong>Car</strong></p>
    <label>Year(enter 0000 if unknown):
    <select name="year">
        <option>0000</option>
      <option>1900</option>
    </select>
    </label>
  <p>
 <input type="submit" value="Enter Car">
</form>
</body>


Now here's my script.php page:
--------------------------------------------------------
<?

$DBhost = "xxx";
$DBuser = "xxx";
$DBpass = "xxx";
$DBName = "xxx";
$table = "cars_spotted";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select database $DBName");

$sqlquery = "INSERT INTO $table VALUES('$_POST[year]','$_POST[date_range]','$_POST[make]','$_POST[model]','$_POST[condition]','$_POST[state]','$_POST[city-county]','$_POST[for_sale]')";



$results = mysql_query($sqlquery);

mysql_close();

print "<html><body><center>";
print "<p>You have just entered this record<p>";
print "Year : $year<br>";
print "Date-Range : $date_range<br>";
print "Make : $make<br>";
print "Model : $model<br>";
print "Condition : $condition<br>";
print "State : $state<br>";
print "For-Sale : $for_sale<br>";

print "</body></html>";
?>


I can't get anything to post or to display on the screen.  I edited out the connection details.  

Start Free Trial
 
Loading Advertisement...
 
[+][-]09.25.2007 at 10:00AM PDT, ID: 19957227

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.25.2007 at 10:14AM PDT, ID: 19957348

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP and Databases
Tags: data, enter, php, database, form
Sign Up Now!
Solution Provided By: DrNikon224
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_1_20070628