Jump to content


Photo

Forms into SQL database


  • Please log in to reply
2 replies to this topic

#1 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 19 September 2006 - 08:31 AM

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?

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 19 September 2006 - 10:39 AM

make them MySQL safe, I have built my own function for this
<?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;
}
?>

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

<?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();
}
?>

Tell me the problem, I will try tell you the solution

#3 ltoto

ltoto
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 19 September 2006 - 10:58 AM

right, i will give this a go and let you know how i get on, thanks a lot




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users