Forum Moderators: open

Message Too Old, No Replies

populating sql database with form data

         

tfling

6:07 pm on Jul 17, 2006 (gmt 0)

10+ Year Member



I am currently using a PHP Script to take my data from an HTML form and email to me, but I would also like to have a sql database populated with that same information. How can I go about doing this?

volatilegx

3:59 pm on Jul 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, tfling :)

The PHP script can access the database, then send a query which will save the data into the database. PHP has built-in functions to handle these tasks.

You can find reference material on the topic here: [us2.php.net...]

Here's some stripped-down, simple code:

# open a connection to the database
@ $db = mysql_pconnect("localhost", "username", "password");
mysql_select_db("databasename");

# send a query
$query = "INSERT INTO 'tablename' ('ID','FIELD1','FIELD2') VALUES ('','".addslashes($somedata)."','".addslashes($someotherdata)."');
$result = mysql_query($query);
if (!$result) { echo mysql_error();}

eelixduppy

4:20 pm on Jul 18, 2006 (gmt 0)



Related threads:

Good luck!