hai guyz....

Reply

Join Date: Aug 2008
Posts: 8
Reputation: sahdev86 is an unknown quantity at this point 
Solved Threads: 0
sahdev86 sahdev86 is offline Offline
Newbie Poster

hai guyz....

 
0
  #1
Sep 25th, 2008
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...



  1. <?php
  2.  
  3. /* fetch data from form input */
  4.  
  5. EXTRACT ($_POST);
  6.  
  7. /* connect to server */
  8.  
  9. $db = mysql_connect("localhost", "root", "") OR die ("Could Not Connect to Server" . mysql_error());
  10.  
  11. /* select database */
  12.  
  13. mysql_select_db("webauth", $db) OR die ("Could Not Find Database" . mysql_error());
  14.  
  15.  
  16. /* fields' names in the database */
  17. $result = "INSERT INTO buy (id,type,price,desc,email,apartment,roomno,qty)";
  18.  
  19. /* variable name as declared as above to be entered to the field */
  20. $result .= "VALUES ('$id', '$type', '$price','$desc','$email','$apartment','$roomno','$qty')";
  21.  
  22. mysql_query($result, $db);
  23.  
  24.  
  25. /* variable name as declared as above to be entered to the field */
  26. /* fields' names in the database */
  27. /* execute the query */
  28.  
  29. echo "successful";
  30. echo "<br>";
  31. echo "<a href=order.php>Home</a>";
  32. mysql_close($db);
  33.  
  34.  
  35. ?>
Last edited by peter_budo; Sep 25th, 2008 at 4:44 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: hai guyz....

 
0
  #2
Sep 25th, 2008
You should start trying to use transactions, that way if there was an error, any changes that successfully went through are also rolled back.

  1. <?php
  2. $debug = true;
  3. //variable to commit transaction
  4. $commit = "commit";
  5. $errors = array();
  6.  
  7. /* fetch data from form input */
  8.  
  9. extract ($_POST);
  10.  
  11. /* connect to server */
  12.  
  13. if(!$db = mysql_connect("localhost", "root", ""))
  14. {
  15. $errors[] = mysql_error();
  16. }
  17.  
  18. /* select database */
  19.  
  20. if(!mysql_select_db("webauth", $db))
  21. {
  22. $errors[] = mysql_error();
  23. }
  24.  
  25. //begin transaction
  26. if(!mysql_query("begin"))
  27. {
  28. $errors[] = mysql_error();
  29. }
  30.  
  31. /* fields' names in the database */
  32. $result = "INSERT INTO buy (id,type,price,desc,email,apartment,roomno,qty)";
  33.  
  34. /* variable name as declared as above to be entered to the field */
  35. $result .= "VALUES ('$id', '$type', '$price','$desc','$email','$apartment','$roomno','$qty')";
  36.  
  37. if(!mysql_query($result, $db))
  38. {
  39. $commit = "rollback";
  40. $errors[] = mysql_error();
  41. }
  42.  
  43.  
  44. //$commit = "rollback"; //uncomment to automatically rollback the transaction
  45.  
  46. if($commit == "commit")
  47. {
  48. mysql_query($commit);
  49. echo "successful";
  50. echo "<br>";
  51. echo "<a href=order.php>Home</a>";
  52. mysql_close($db);
  53. }
  54. else
  55. {
  56. echo "there was an error in your transaction, transction rolled back: ";
  57. if($debug == true)
  58. {
  59. foreach($errors as $value)
  60. {
  61. echo "<p>" . $value . "</p>";
  62. }
  63. }
  64. mysql_query($commit);
  65. mysql_close($db);
  66. }
  67. /* variable name as declared as above to be entered to the field */
  68. /* fields' names in the database */
  69. /* execute the query */
  70.  
  71.  
  72. ?>
“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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 8
Reputation: sahdev86 is an unknown quantity at this point 
Solved Threads: 0
sahdev86 sahdev86 is offline Offline
Newbie Poster

Re: hai guyz....

 
0
  #3
Sep 29th, 2008
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...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC