the following page just reloads the default case when pressing submit. i've been checking for hours now and can't find my mistake, please help. When you fill out the form and press submits the pages just reloads the form, and the variables are still blank. Thanks in advance.
<?php
$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error()); }
function add() {
global $con;
include "header.php";
mysql_select_db("db", $con);
$result = mysql_query("SELECT * FROM cat");
echo "<span class=\"blackText\">
<center>
<form action=\"admin.php\" method=\"post\">
Year: <input type=\"text\" name=\"year\" /><br />
Make: <input type=\"text\" name=\"make\" /><br />
Model: <input type=\"text\" name=\"model\" /><br />
Price: <input type=\"text\" name=\"price\" /><br />
Cat: <select name=\"cat\">";
while($row = mysql_fetch_array($result))
{
echo "<option value=\"".$row['id']."\">".$row['cat']."</option>";
}
mysql_close($con);
echo "</select>
<input type=\"hidden\" name=\"op\" value=\"insertnew\">
<input type=\"submit\" value=\"Add\"></form>
$year - $make - $model - $price - $cat";
}
function insertnew($year, $make, $model, $price, $cat) {
global $con;
include "header.php";
mysql_select_db("db", $con);
$sql="INSERT INTO unit (year, make, model, price, cat)
VALUES
('$_POST[year]','$_POST[make]','$_POST[model]','$_POST[price]','$_POST[cat]')";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
}
switch($op) {
case "insertnew":
insertnew($year, $make, $model, $price, $cat);
break;
default:
add();
break;
}
?>