MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 29th, 2004, 01:51 AM
Jokes Jokes is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: FL
Posts: 3 Jokes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Jokes
Question INSERT INTO mysql problem from a form.

Hey all!

I am new here, and new to php and mysql, but I will make this pretty short (at least try to). I am working on setting up at least the basics...a user list. I have made a usertest.htm page (form) and i am using it to POST to usertest.php and trying to have the information the user had input in the form, inserted into the database via the php page. I do keep comming up with different errors, trying my " and ' and () in different positions. Originally I was getting parse errors, but I seem to have fixed those, now just getting the error I posted at the bottom with the mysql query syntax. I know how to do forms, and the php page is quite short, so heres the code, hope someone can help

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

mysql_connect("host","usr","pass") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("database") or die ("Unable to select requested database.");

//Assign contents of form to variables
$user = $_POST['user'];
$password = $_POST['password'];
$shard = $_POST['shard'];
$email = $_POST['email'];
$im = $_POST['im'];
$icq = $_POST['icq'];

mysql_query ( "INSERT INTO visitors (user, password, shard, email, im, icq) VALUES ($user, $password, $shard, $email, $im, $icq)" );

echo mysql_error();
mysql_close();

?>

</body>
</html>

The error comes up as:

You have an error in your SQL syntax near '@email, im, icq)' at line 1

It seems that i am close to getting it right, because the information IS being passed to the .php page, but not quite making it to the database table. It also seems that it is accepting the first 3 values, but once it hits the @ sign it becomes a problem from there? Is that something that cannot be used in an insert command as a value passed from my variable?...and of course, the previous information before the @ does not make it into the table.

Any thoughts, hints, corrections or guides i can refer to would be wonderful. Thanks in advance gang, and i hope to contribute rather than inquire as time goes on

OH! One other thing, I would like to include what the user had input on the htm page so they can see what information they had posted to make sure there are no errors. I would imagine it would just be a simple Echo command to do this, and I would also just put the comment on the bottom of the page stating Thanks for submitting your information. I know there are many ways to do this, but its late, and I am beginning to ramble so I will leave it at that. My main concern is getting the info into the table from my form.
Night for now.
Jokes

Reply With Quote
  #2  
Old January 29th, 2004, 07:57 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
String values need to be quoted when being updated or inserted into mysql:

PHP Code:
 mysql_query "INSERT INTO visitors (user, password, shard, email, im, icq) VALUES ('" $user "','" $password "','" $shard "','" $email "','" $im "','" $icq "')" ); 

Reply With Quote
  #3  
Old January 29th, 2004, 12:50 PM
Jokes Jokes is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: FL
Posts: 3 Jokes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Jokes
Thumbs up Thankyou!

Thanks Houston.....we have a go and a good insert

Now my brain can work on even more boggling problems lol, i had tried everything except for putting the periods on each side of the variables in the string to be inserted.

I didn't even know they needed to be there!...but...as we see here folks, you live, you inquire...and you shall learn...i know i just did lol!

Anyway, thanks again for the help, and I am sure you will be seeing more posts and questions from me as I work my way blindly through my little project. *cheers*....its almost friday!

Reply With Quote
  #4  
Old January 29th, 2004, 01:48 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
No problem. Hope you'll stick around. Don't be shy about posting in some of the non-programmer forums.

Reply With Quote
  #5  
Old January 29th, 2004, 03:34 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
I realize dhouston's way works... but you could also do this:
PHP Code:
 mysql_query "INSERT INTO visitors (user, password, shard, email, im, icq) VALUES ('$user','$password','$shard','$email','$im','$icq  ')" ); 


You might run into problems when dealing with arrays, or methods with return values.

[just had to throw my two cents in]

Reply With Quote
  #6  
Old January 29th, 2004, 05:16 PM
Jokes Jokes is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: FL
Posts: 3 Jokes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Jokes
I beleive I tried that, except for one difference.....

I beleive I tried that method MadCowDzz. Only difference with the way I did it, was i had a space after each comma, but hence, I got errors on it that way.

Its working well with the first example, so since I'm a smart beginner, and figure I was always taught don't fix it if it ain't broke, I will leave that one particular query alone

Just to keep ya'll updated, It is posting correctly, and even detects if someone has input a duplicate name, which i set unique as to not allow that. Is there a "neater" way to display the error that tells the submitter he needs to pick another name?

Right now once a user submits the page, the info goes in, but ummm....they go to a blank page (the processor)....*that can't be good, he thinks to himself* Where to go next.....hrmm....

Reply With Quote
  #7  
Old April 26th, 2004, 03:11 PM
moguelator moguelator is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 3 moguelator User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
INSERT INTO visitors (user, password, shard, email, im, icq) VALUES ('$user','$password','$shard','$email','$im','$icq ')

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > INSERT INTO mysql problem from a form.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT