Welcome to WebmasterWorld Guest from 107.21.175.43

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Using PHP to write form data in to MySQL

Lost, confused, and desperate-

     

SEO Speedster

12:05 am on Nov 5, 2001 (gmt 0)



I am having great pains trying to get my form data into a mySQL database - and cannot find any suitable resources out there to help me out. I'm not a big PHP guy, or a MySQL guy, so pardon my inaccuracies or faults here!

I am used to ASP and SQL Server, and typically, I use a request.form(fieldname) to get the form contents, then I will insert it into my SQL statement...

But how on earth do you get form values in PHP to be put into a mySQL database.

It would be ideal if there were a script out there, written in PHP that collects all the form data and puts it into a nice SQL string for insertion... Assuming of course that the field names in the form are the same as the column names in the table.

Any chance I'd get lucky on this one?

Thanks if so~
~ Speedster

sugarkane

11:38 am on Nov 5, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP will automatically place form values into variables, so you don't need to worry about retrieving the contents of the form.

Say you had form fields called 'foo', 'bar' and 'baz' that you wanted to insert into a table 'widgets' with columns 'one', 'two' and 'three', your PHP would look something like:

$query="INSERT INTO widgets (one, two, three) VALUES ('$foo', '$bar', '$baz')";
mysql_query($query, $mysql_link);

Hope this helps

SEO Speedster

2:20 pm on Nov 5, 2001 (gmt 0)



thank you sugarkane! I will make an attempt at the script again later today when more time becomes available - of course it's a monday! ;)

Again, much thanks.
~ Speedster

 

Featured Threads

Hot Threads This Week

Hot Threads This Month