Web Hosting Talk







View Full Version : forms using php and databases? tutorials please???


spiderfine
09-18-2005, 10:12 AM
Hello everyone,

I was wondering is someone could point me in the right direction:

I would like to put a form on my site that does not send the results to my email box, but to a file, database or whatever you call it. I'm not very knowledgeable in mysql (is that something i need?)...oh boy i don't even really know the correct lingo here, but i've already set up the form using html and php and email, but is there a tutorial here in wht??

thank you

spiderfine

flakdesign
09-18-2005, 11:04 AM
u can have form action attribute as

<form action="process.php>

in the process.php get all the form elements value with $_REQUEST['name']; or $_http_post_vars['name']

get the all the values and then insert into sql database.. Google for sql tutorials, there r lots of them..

michael.j.fox
09-29-2005, 11:51 PM
Interfacing with MySQL would be your way to go. It is very powerful. It is a little overwhelming at first, but you can do wonders with it. It allows you to create truly dynamic content.

There are lots of good books on interfacing PHP with MySQL, as it can be very complicated.

spiderfine
10-03-2005, 09:33 AM
thank you very much for your advise. i'm trying

michael-lane
10-13-2005, 03:50 AM
yeah mysql is the way to go. I only learnt it a year ago. and i'm already seeing its wonders. I reccommend webmonkey's tutorial on php and mysql thats where i learnt. took me 2 reads.

spiderfine
10-14-2005, 11:26 AM
very interesting...thank you.

Aran11
08-03-2010, 04:23 PM
You can easily make a PHP script that does both email and submit the form to a MySQL database.

Here is a simple example:

sql.php - Used to make a connection to your MySQL Database

<?php
mysql_connect("localhost", "USERNAME", "PASSWORD") or die(mysql_error());
mysql_select_db("DB NAME") or die(mysql_error());
?>

form.php - The page your form will be on

<?php
//This will include the MySQL connection file we just created
include_once("sql.php");

//This will check if the form has been submitted and if so will insert into the DB
if(isset($_POST['name'])){
//This will check if the value submitted was NULL or blank, if so then it will warn the user and will not process the form
if($_POST['name'] == ""){
echo "<b>Please make sure to fill out the field before submitting.</b>";
} else {
//If form was completed alright, then it will insert into the database, however if any errors with will be printed out to help you debug any errors.
mysql_query("INSERT INTO `table-name` SET `name` = '".$_POST['name']."'") or die(mysql_error());
}
}
?>
<form name="name" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
<input type="text" name="name">
<input type="submit" value="Add name to database">
</form>


What th