Hi
I'm pretty new to PHP, and am just learning it now. I know that in order to really get this project working exceptionally well is to just learn one step at a time. Here, I'm trying to simply enter data to a table on a MYsql database. I know that 'how' to do this is all over the internet, but getting applications to work correctly is another. I've written a simple form where the user enters data, using PHP I would like to have that data written to the table I have created in the MySql database.
At present, the situation is as follows: when an individual fills out the form, and submits it, they get the following error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(first,last,phone,mobile,fax,email,web) VALUES ('test','from','
I'm Using Version 4
The following is the written PHP code:
php:
<?
$username="myusername";
$password="my password";
$database="my database";
$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$web=$_POST['web'];
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO $my table (first,last,phone,mobile,fax,email,web) VALUES ('$first','$last','$phone','$mobile', '$fax', '$email', '$web')";
mysql_query($query);
?>
Here is the HTML script for the form:
<form action="myphpfilegoeshere.php" method="post">
First Name: <input type="first" name="first"><br>
Last Name: <input type="last" name="last"><br>
Phone: <input type="phone" name="phone"><br>
Mobile: <input type="mobile" name="mobile"><br>
Fax: <input type="fax" name="fax"><br>
E-mail: <input type="email" name="email"><br>
Web: <input type="web" name="web"><br>
<input type="Submit">
mysql_query($query) or die(mysql_error());
</form>
Can anyone see where the error is? I would appreciate anyone's assistance helping me understand where the syntax is wrong. THanks
THANK YOU VERY MUCH
Last edited by surf142248; 12-19-2005 at 02:01 PM..
|