Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Using a form to enter data in to a database using PHP
Old 12-19-2005, 01:57 PM Using a form to enter data in to a database using PHP
Junior Talker

Posts: 1
Trades: 0
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..
surf142248 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-20-2005, 09:21 AM
reli4nt's Avatar
Extreme Talker

Posts: 168
Location: New York
Trades: 0
I take it $my and table are actually $mytable substituting for the real name of the table?
It looks from here like you may have
PHP Code:
INSERT INTO users table (first,last,phone,mobile,fax,email,webVALUES ('$first','$last','$phone','$mobile''$fax''$email''$web')
as you actually output.
__________________

Please login or register to view this content. Registration is FREE

Designing the world we live in.
Defining the terms we live by.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
Reply     « Reply to Using a form to enter data in to a database using PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11217 seconds with 12 queries