I try to add data into database.. but i unable do that can any want help me to solve this problem? Add Data : <form action="add_process.php" method="post"> <p>Name: <input type="text" name="name"> <br> Address: <input type="text" name = "address" /> <br Country: <input type="text" name = "country"> <br /> City: <input name = "text" type="text" id="city" /> <br /> Suburb: <input name = "text" type="text" id="suburb" /> <br /> Telephone No: <input name = "text" type="text" id="telephone" /> </p> Cuisine: <input name = "text" type="text" id="cuisine" /> <br /> Food: <input name = "text" type="text" id="food" /> <p><br> <input type="submit" value="Submit"> </p> </form> Connection Coding : <? $fname=$_POST['name']; $faddress=$_POST['address']; $fcountry=$_POST['country']; $fcity=$_POST['city']; $fsuburb=$_POST['suburb']; $ftelephone=$_POST['telephone']; $fcuisine=$_POST['cuisine']; $ffood=$_POST['food']; mysql_connect("localhost", "webzwork_red", "58281044") or die(mysql_error()); mysql_select_db("webzwork_red") or die(mysql_error()); mysql_query("INSERT INTO `users` VALUES ('$fname', '$faddress', '$fcountry', '$fcity', '$suburb', '$ftelephone', '$cuisine', '$ffood')"); Print "Your information has been successfully added to the database."; ?>
first off all, your form is designed wrong. You have multiple item named 'text' try using <form action="" method="post"> <p>Name: <input type="text" name="name"> <br> Address: <input type="text" name = "address" /> <br /> Country: <input type="text" name = "country" /> <br /> City: <input type="text" id="city" name="city" /> <br /> Suburb: <input type="text" id="suburb" name="suburb" /> <br /> Telephone No: <input type="text" id="telephone" name="telephone" /> </p> Cuisine: <input type="text" id="cuisine" name="cuisine" /> <br /> Food: <input type="text" id="food" name="food" /> <p><br> <input type="submit" value="Submit"> </p> </form> Code (markup): this should work
try putting your variables between {} in queries: like I show bellow mysql_query("INSERT INTO `users` VALUES ('{$fname}', '{$faddress}', '{$fcountry}', '{$fcity}', '{$suburb}', '{$ftelephone}', '{$cuisine}', '{$ffood}')"); Code (markup):
still same.. check this site webzworks.com/web_project_2008/red/login/add.php webzworks.com/web_project_2008/red/login/add_process.php
in the form page put <form action="add_process.php" method="post"> Code (markup): I have removed add_process.php, when i tested on my site. If still does not work, post here the code of add_process.php, or PM-it to me
add_porcess.php <? $fname=$_POST['name']; $faddress=$_POST['address']; $fcountry=$_POST['country']; $fcity=$_POST['city']; $fsuburb=$_POST['suburb']; $ftelephone=$_POST['telephone']; $fcuisine=$_POST['cuisine']; $ffood=$_POST['food']; mysql_connect("localhost", "webzwork_red", "58281044") or die(mysql_error()); mysql_select_db("webzwork_red") or die(mysql_error()); mysql_query("INSERT INTO `users` ('name','address','country','city','suburb','telephone','cuisine','food')VALUES ('{$fname}', '{$faddress}', '{$fcountry}', '{$fcity}', '{$suburb}', '{$ftelephone}', '{$cuisine}', '{$ffood}')"); Print "Your information has been successfully added to the database."; ?>
$con = mysql_connect("localhost", "webzwork_red", "58281044") or die(mysql_error()); mysql_select_db("webzwork_red",$con ) or die(mysql_error()); mysql_query("INSERT INTO `users` ('name','address','country','city','suburb','telephone','cuisine','food')VALUES ('{$fname}', '{$faddress}', '{$fcountry}', '{$fcity}', '{$suburb}', '{$ftelephone}', '{$cuisine}', '{$ffood}')",$con ); Code (markup):
this is mysql file. i not sure whether is correct or not pls advice !note : i can't add new records -- phpMyAdmin SQL Dump -- version 2.11.4 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Mar 17, 2008 at 05:51 PM -- Server version: 4.1.22 -- PHP Version: 5.2.3 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `webzwork_red` -- -- -------------------------------------------------------- -- -- Table structure for table `users` -- CREATE TABLE `users` ( `no` int(16) NOT NULL auto_increment, `fname` varchar(30) NOT NULL default '', `faddress` varchar(255) NOT NULL default '', `fcountry` varchar(255) NOT NULL default '', `fcity` varchar(255) NOT NULL default '', `fsuburb` varchar(255) NOT NULL default '', `ftelephone` varchar(255) NOT NULL default '', `fcuisine` varchar(255) NOT NULL default '', `ffood` varchar(255) NOT NULL default '', PRIMARY KEY (`no`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ; -- -- Dumping data for table `users` -- INSERT INTO `users` VALUES(1, 'Al Mirjan Café', 'Lot 415, Level 4, Suria KLCC, 50088 Kuala Lumpur', 'Malaysia', 'Kuala Lumpur', 'City Centre', '603 2168 8557', 'Middle East', 'Standard'); INSERT INTO `users` VALUES(2, 'Chef Choi', '159, Jalan Ampang, 50450 Kuala Lumpur', 'Malaysia', 'Kuala Lumpur', 'City Centre', '603 2163 5866', 'Chinese', 'Fine Dining'); INSERT INTO `users` VALUES(3, 'Khaana Peena', 'E-01-04/05 Plaza Mont'' Kiara, 2 Jalan Kiara, Kuala Lumpur', 'Malaysia', 'Kuala Lumpur', 'Mont Kiara', '603 6201 3355', 'Indian', 'Fine Dining'); INSERT INTO `users` VALUES(4, 'Seafood Paradise', '8, Jalan Conlay, 50450 Kuala Lumpur', 'Malaysia', 'Kuala Lumpur', 'City Centre', '603 2143 1101', 'International', 'Seafood'); INSERT INTO `users` VALUES(5, 'Tamarind Hill', '1, Jalan Kerja Air Lama, 68000 Ampang, Selangor', 'Malaysia', 'Kuala Lumpur', 'City Centre', '603 4256 9100', 'Indo-chinese', 'Fine Dining'); INSERT INTO `users` VALUES(6, 'The Rib Shop', '120-122, Jalan Kasah, Damansara Heights, 50490 Kuala Lumpur', 'Malaysia', 'Kuala Lumpur', 'Damansara Heights', '603 2095 9729', 'Western', 'Steaks'); INSERT INTO `users` VALUES(7, 'Alexis', '29, JalanTelawi 3, Bangsar Baru, 59100 Kuala Lumpur', 'Malaysia', 'Kuala Lumpur', 'Bangsar', '603 2284 2880', 'Fusion', 'Standard'); INSERT INTO `users` VALUES(8, 'Annalakshmi', 'Lot G(E) 017,Ground Floor, Mid Valley Megamall, Mid Valley City, Lingkaran Syed Putra, 59200 Kuala Lumpur', 'Malaysia', 'Kuala Lumpur', 'Mid Valley', '603 7725 4164', 'Indian', 'Fine Dining'); INSERT INTO `users` VALUES(9, 'Antonio''s Calabria', '32, Jalan Wan Kadir 4, Off Jalan Damansara, Taman Tun Dr Ismail, 60000 Kuala Lumpur', 'Malaysia', 'Kuala Lumpur', 'Taman Tun Dr Ismail', '603 7725 4164', 'Italian', 'Standard'); INSERT INTO `users` VALUES(10, 'Aoyama The Green Room', 'No.10 (Ground Floor), Jalan 27/70A, Desa Sri Hartamas, 50480 Kuala Lumpur', 'Malaysia', 'Kuala Lumpur', 'Sri Hartamas', '603 2300 0683', 'Japanese', 'Standard');
your insert statement is wrong check the table names you write mysql_query("INSERT INTO `users` ('name','address','country',.... but your column names are starting with f like mysql_query("INSERT INTO `users` ('fname','faddress','fcountry',....
i try change the "post" as u told. but i still facing the same problem is my primary key correct in my database?
this is the correct version mysql_query("INSERT INTO `users` (no,'fname','faddress','fcountry','fcity','fsuburb','ftelephone','fcuisine','ffood')VALUES ('','{$fname}', '{$faddress}', '{$fcountry}', '{$fcity}', '{$suburb}', '{$ftelephone}', '{$cuisine}', '{$ffood}')",$con ); Code (markup): watch the table column names
This is correct for your problem.. <? $fname=$_POST['name']; $faddress=$_POST['address']; $fcountry=$_POST['country']; $fcity=$_POST['city']; $fsuburb=$_POST['suburb']; $ftelephone=$_POST['telephone']; $fcuisine=$_POST['cuisine']; $ffood=$_POST['food']; echo $fname; echo '<br>'; echo $faddress; echo '<br>'; echo $fcountry; echo '<br>'; echo $fcity; echo '<br>'; echo $fsuburb; $conns=mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("webzwork_red") or die(mysql_error()); $query="INSERT INTO users VALUES ('','$fname', '$faddress', '$fcountry', '$fcity', '$suburb', '$ftelephone', '$cuisine', '$ffood')"; $result=mysql_query($query,$conns) or die(mysql_error()); Print "Your information has been successfully added to the database."; ?> And it is for your input form .. <form action="add_process.php" method="POST"> <p>Name: <input type="text" name="name"> <br> Address: <input type="text" name = "address" /> <br> Country: <input type="text" name = "country"> <br /> City: <input name = "city" type="text" id="city" /> <br /> Suburb: <input name = "suburb" type="text" id="suburb" /> <br /> Telephone No: <input name = "telephone" type="text" id="telephone" /> </p> Cuisine: <input name = "cuisine" type="text" id="cuisine" /> <br /> Food: <input name = "food" type="text" id="food" /> <p><br> <input type="submit" value="Submit"> </p> </form>