php form values into a databse

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
heshan
Forum Commoner
Posts: 26
Joined: Tue Jul 13, 2010 1:16 pm

php form values into a databse

Post by heshan »

Can anyone knows how to insert date of birth and gender values of a particular user into the database?

They are included in a registration form.

Thank You,
Heshan.
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: php form values into a databse

Post by buckit »

theform.htm

Code: Select all

<form method='post' action='usetheform.php'>
<input type='text' name='dob'>
<input type='text' name='gender'>
<input type='submit' name='submit'>
</form
usetheform.php

Code: Select all

//open database connection
//set variables from form (this is a good time to sanitize them (google 'php sanitize form input'))
$dob = $_POST['dob'];
$gender= $_POST['gender'];
//execute this sql statement
INSERT INTO users (dob,gender) VALUES ({$dob}, {$gender}
again... google 'php sanitize form input'. or search here on the forums.

If you dont know how to get a connection to your DB then go to http://www.w3schools.com/PHP/php_mysql_connect.asp.

this should help you in the right direction.
Post Reply