Jump to content

Forms into SQL database


ltoto

Recommended Posts

What I am im doing is there is an initial form where they can fil in the details required, and then there will be an option to select, Villa, Hotel or Appartments ( the type of accomodation they want and after they sumbit the first form, depending on what option of them three they chose it goes through to another form.

what i need to know is how to get the details of the form into the database if that makes sense, but also the person who is filling in the form will be given a reference number( kinda how a data is done ) which will follow them through both forms.


any ideas or do i need to give more information?
Link to comment
https://forums.phpfreaks.com/topic/21247-forms-into-sql-database/
Share on other sites

make them MySQL safe, I have built my own function for this
[code]
<?php
function MakeSafe($str, $make_lower = false){
if($make_lower){
$str = strtolower($str);
}
$str = stripslashes($str);
$str = trim($str);
$str = strip_tags($str);
$str = mysql_real_escape_string($str);
return $str;
}
?>
[/code]

so if we have field names "name" AND "email"
We create a table in the MySQL Database, with a
FIELD NAME: id_num
TYPE: int(50)
Primary Key
AUtoIncrement

and also 2 varchars, with name and email

then

[code]
<?php
function DBConnect(){
$db = mysql_connect("localhost","username","password");
//Replace username and password with yours, host is normally localhost
mysql_select_db("DB_Name",$db);
//Replace DB_Name with the Database name
}

$name = MakeSafe($_POST["name"]);
$email = MakeSafe($_POST["email"]);

$query1 = "INSERT INTO tablename (name, email) VALUES ('".$name."', '".$email."');
$result1 = mysql_query($query1);

if($result1){

echo "The data has been added to the Database."<br />\n";
}else{
echo "There has been an error<br />\n"
.mysql_error();
}
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.