| | |
hai guyz....
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2008
Posts: 8
Reputation:
Solved Threads: 0
hai guyz...1st of all i would lik 2 thank to those who teach me on how to do an announcement...now i got new problem...im doin online food delivering system within campus...so user can view the food and if the user click buy, they can view the name, price n description of the food. So the user need to key in their email,apartment name , room number and quantity. so it wil store into database and the admin can view the name, price n description of the food plus user email,apartment name , room number and quantity ...the problem now is after i key in everthing and click buy it show that the order is successfuly sent but the db is empty.I hope somebody can solve my problem....below is my script....10q...
sql Syntax (Toggle Plain Text)
<?php /* fetch data from form input */ EXTRACT ($_POST); /* connect to server */ $db = mysql_connect("localhost", "root", "") OR die ("Could Not Connect to Server" . mysql_error()); /* select database */ mysql_select_db("webauth", $db) OR die ("Could Not Find Database" . mysql_error()); /* fields' names in the database */ $result = "INSERT INTO buy (id,type,price,desc,email,apartment,roomno,qty)"; /* variable name as declared as above to be entered to the field */ $result .= "VALUES ('$id', '$type', '$price','$desc','$email','$apartment','$roomno','$qty')"; mysql_query($result, $db); /* variable name as declared as above to be entered to the field */ /* fields' names in the database */ /* execute the query */ echo "successful"; echo "<br>"; echo "<a href=order.php>Home</a>"; mysql_close($db); ?>
Last edited by peter_budo; Sep 25th, 2008 at 4:44 pm. Reason: Keep It Organized - please use [code] tags
You should start trying to use transactions, that way if there was an error, any changes that successfully went through are also rolled back.
php Syntax (Toggle Plain Text)
<?php $debug = true; //variable to commit transaction $commit = "commit"; $errors = array(); /* fetch data from form input */ extract ($_POST); /* connect to server */ if(!$db = mysql_connect("localhost", "root", "")) { $errors[] = mysql_error(); } /* select database */ if(!mysql_select_db("webauth", $db)) { $errors[] = mysql_error(); } //begin transaction if(!mysql_query("begin")) { $errors[] = mysql_error(); } /* fields' names in the database */ $result = "INSERT INTO buy (id,type,price,desc,email,apartment,roomno,qty)"; /* variable name as declared as above to be entered to the field */ $result .= "VALUES ('$id', '$type', '$price','$desc','$email','$apartment','$roomno','$qty')"; if(!mysql_query($result, $db)) { $commit = "rollback"; $errors[] = mysql_error(); } //$commit = "rollback"; //uncomment to automatically rollback the transaction if($commit == "commit") { mysql_query($commit); echo "successful"; echo "<br>"; echo "<a href=order.php>Home</a>"; mysql_close($db); } else { echo "there was an error in your transaction, transction rolled back: "; if($debug == true) { foreach($errors as $value) { echo "<p>" . $value . "</p>"; } } mysql_query($commit); mysql_close($db); } /* variable name as declared as above to be entered to the field */ /* fields' names in the database */ /* execute the query */ ?>
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
•
•
Join Date: Aug 2008
Posts: 8
Reputation:
Solved Threads: 0
10x for the code Mrr.Robbob....but there is a syntax error in the code...if i delete id,type,price n desc...the code works wel...for ur information the id,type,price n desc wil display automatically wen user click the food picture...the user only keyin the email,roomno,apartment and quantity...but the db mus show id,type,price,desc,email,roomno,apartment n quantity....can u help me wit these Mr.Robbob...
![]() |
Other Threads in the PHP Forum
- Previous Thread: regarding image
- Next Thread: how can i learn web programming languages from the scratch
| Thread Tools | Search this Thread |
apache api array beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external fcc file files folder form forms forum freelancing function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction menu method mlm mod_rewrite multiple mysql neutrality oop pageing pagerank paypal pdf php phpmysql play problem query question radio random recursion remote root script search select server sessions sms soap source space sql support! syntax system table template tutorial update upload url validator variable video web youtube





