php forms help

1Tsme1941

Member
Hi guys, I'm trying to create a form to insert data into database and losing.
here is my code. Any help?
-------------------------------------------------------------------------------------
<!DOCTYPE html><html>
<head>

</head>
<body>
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
echo "User Has submitted the form and entered this name : <b> $name </b>";
echo "<br>You can use the following form again to enter a new name.";
}
?>
<form name="test" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<input type="text" size="5" name="id">id<br />
<input type="text" size="25" name="first name">first name<br />
<input type="text" size="25" name="last name">last name<br />
<INPUT TYPE="text" size=25 name="email">email<br />
<INPUT TYPE="text" size=25 name="address1">address1<br />
<INPUT TYPE="text" size=25 name="apt">apt<br />
<input type="text" size="25" name="city">city<br />
<input type="text" size="2" name="state">state<br />
<INPUT TYPE="text" size=6 name="zip-code">zip-code<br />
<INPUT TYPE="text" size=10 name="body-style">body-style<br />
<input type="text" size="35" name="unit-price">unit-price<br />
<INPUT TYPE="text" size=1 name="qty">qty<br />
<INPUT TYPE="text" size=6 name="color">color<br />
<input type="text" size="255" name="question">question<br />
<input type="submit" name="submit" value="Submit Form"><br>
</form>
</body></html>

<?php
include_once 'db.php';
if(isset($_POST['submit']))
{
$id=$_POST['id']; $first name=$_POST['first name']; $last name=$_POST['last name'];
$email=$_POST['email']; $address1=$_POST['address1']; $apt=$_POST['apt']; $city=$_POST['city'];
$state=$_POST['state']; $zip-code=$_POST['zip-code'];$body-style=$_POST['body-style'];
$unit-price=$_POST['unit-price']; $qty=$_POST['qty']; $color=$_POST['color'];
$question=$_POST['question'];

$sql = "INSERT INTO saledata (id,first name,last name,email,address1,apt,city,state,zip-code,
body-style,unit-price,qty,color,question)
VALUES ('$id','$first name','$last name','$email','$address1','$apt','$city','$state','$zip-code',
'$body-style','$unit-price','$qty','$color','$question')";

if (mysqli_query($conn, $sql)) {
echo "New record has been added successfully !";
} else {
echo "Error: " . $sql . ":-" . mysqli_error($conn);
}
mysqli_close($conn);
}
?>
------------------------------------------------------
here is code for "db.php"
 
Top