Forum Moderators: open
so i have a form with the following on it :
I amnot even getting anything in the database . I have tried arrays , serialization ect can any one help me?Please
<html>
<head>
<title>hello</title>
</head>
<body>
<form action="add_contact.php" method="post">
Name: <input type="text" name="name"/>
Address1: <input type="text" name="Address1"/>
Address2: <input type="text" name="Address2"/>
Address3: <input type="text" name="Address3"/>
suburb: <input type="text" name="Suburb"/>
City: <input type="text" name="City"/>
Area: <input type="text" name="Area"/>
Province: <input type="text" name="Province"/>
Country: <input type="text" name="Country"/>
Tel: <input type="number" name="Tel"/>
Rooms: <input type="number" name="Rooms"/>
Description: <input type="text" name="Description"/>
POBox: <input type="number" name="POBox"/>
<input type="Submit"/>
</form>
</body>
</html>
I have the php form as the following :
<?php
$DBhost="localhost";
$DBpass= "";
$DBName = "hotel";
$table = "hotel_detail";
$DBuser="root";
$name=$_post['name'];
$address1=$_post['address1'];
$address2=$_post['address2'];
$address3=$_post['address3'];
$suburb=$_post['suburb'];
$city=$_post['city'];
$area=$_post['area'];
$province=$_post['province'];
$country=$_post['country'];
$tel=$_post['tel'];
$rooms=$_post['rooms'];
$description=$_post['description'];
$pobox=$_post['pobox'];
$dbh = mysql_connect($DBhost,$DBuser) or die("Unable to connect to database");
Echo "connected to mysql";
$db_selected = mysql_select_db('Hotel',$dbh) or die(mysql_error());
Echo "dbase selected";
Mysql_query("INSERT INTO Hotel_detail (name,address1,address2,address3,suburb,city,area,
province,country,tel,rooms,description,pobox) VALUES ($name,$address1,$address2,$address3
,$suburb,$city,$area,$province,$country,$tel,$rooms,$description,$pobox)") ;
Echo "dbase selected data entered";
?>
It adds an entry to the database but the entry is blank ... any suggestions would be appreciated!
ysql_query("INSERT INTO Hotel_detail (name,address1,address2,address3,suburb,city,area,
province,country,tel,rooms,description,pobox) VALUES ('$name','$address1','$address2','$address3
','$suburb','$city','$area','$province','$country','$tel','$rooms','$description','$pobox')",$dbh) ;
mysql_query("INSERT INTO Hotel_detail (name,address1,address2,address3,suburb,city,area,province,country,tel,rooms,description,pobox) VALUES ('".$name."','".$address1."','".$address2."','".$address3."','".$suburb."','".$city."','".$area."','".$province."','".$country."','".$tel."','".$rooms."','".$description."','".$pobox."')",$dbh) ;
I'm guessing it's NOT substituting $name, for instance, in your INSERT statement with the VALUE of the $name variable.
[edited by: ZydoSEO at 7:06 pm (utc) on Nov. 29, 2007]
....
$description=$_post['description'];
$pobox=$_post['pobox'];
Do this
echo "name $name adr.1 $address1 city $city";
Just pick a few you know you're submitting, if one works they all should work. If you don't see the values printing to the screen you know there's something wrong with how you're reading the data input, not inserting it into the DB.
you have....name="Address1"...then are pulling it as....['address1']
<smacks head> Also correct, we should have caught this . . . . . LOL . . . forest from the trees . . .
$country=$_post['country'];
$tel=$_post['tel'];
$rooms=$_post['rooms'];
$description=$_post['description'];
$pobox=$_post['pobox'];
You need to asemble the sql in a string first
$sql = "("INSERT INTO Hotel_detail (name,address1,address2,address3,suburb,city,area,province,country,tel,rooms,description,pobox) VALUES (" ;
# now add all ther terms in
$sql = $sql ."'".$name."', "
..
..
# then finish the it off
$sql = $sql .")";
#
you can then easaly echo the sql string and check it in the MYSql Query browser and a copy of the database