I’m brand new to PHP/MYSql and I’m trying to build a form that submits to MYSql. Here’s the form code:
<form action="insert.php" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Phone: <input type="text" name="phone"><br>
<input type="Submit">
</form>
Here’s the insert.php:
<?php
include "db-connect.php";
$first = $_POST['first'];
$last = $_POST['last'];
$phone = $_POST['phone'];
$query = "INSERT INTO users VALUES ('', '$first', '$last', '$phone')";
$result= mysql_query($query);
if($result) {
echo "Data entered Successfully";
} else {
echo "You suck at coding";
}
mysql_close();
?>
Again I’m really new, so if you could explain it to me like I’m 5 that’d be great.
EDIT: I built the table with the myphpadmin gui.
The fields are:
id: INT, Primary, auto-increment
first: varchar (50)
last: varchar (50)
phone: varchar (25)
EDIT2: Following Esailija’s advice I added the mysql_error() function. Here’s the response: “Incorrect integer value: ” for column ‘id’ at row 1″
Try
…where first, last, and phone are the actual names of the fields in your table.
And +1 for replacing echo “You suck at coding” with echo mysql_error(). 🙂