help with my scripot PLEASE!!! anyone?

Reply

Join Date: Jan 2009
Posts: 31
Reputation: gpittingale is an unknown quantity at this point 
Solved Threads: 0
gpittingale gpittingale is offline Offline
Light Poster

help with my scripot PLEASE!!! anyone?

 
0
  #1
Jan 29th, 2009
Can anyone please help here I have a form that i wish the user to select a product from a drop down box and then query it in a mysql then i would like to the user to input a number in the next field the press the submit button, then the form should do some simple maths and display it in the next field. now 3 things my code does not do 1/ the math and display it 2/the user input and the product i would like to remain after the form has been submitted 3/ also can anyone give some idea of how to get the form to calculate without a submitt button. here is my code:
  1. <form action="scdc_selfcompletion.php" method="post">
  2. <select name="bap10">
  3. <option selected="selected">Select One</option>
  4. <option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
  5. <option value="Re-Usable Bags">Re-Usable Bags</option>
  6. <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
  7. <option value="No Stand By">No Stand By</option>
  8. <option value="Use Energy Meter">Use Energy Meter</option>
  9. <option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
  10. <option value="Recycling">Recycling</option>
  11. <option value="Stop Junk Mail">Stop Junk Mail</option>
  12. </select>
  13. </td>
  14. <td width="19%">
  15. <input name="pledging" type="text" id="pledging" maxlength="5" />
  16. </td>
  17. <td>&nbsp;</td>
  18. <td>&nbsp;</td>
  19. </tr>
  20. <tr>
  21. <td colspan = '3'>Total Savings and Expenditure</td>
  22. <td>&nbsp;</td>
  23. <td>&nbsp;</td>
  24. </tr>
  25. </table>
  26. <input type="Submit" name="select" value="select">
  27. </form>
  28. <?php
  29. $select = $_POST['select'];
  30.  
  31. // if something has been chosen
  32. if (!empty($select)) {
  33.  
  34. // get the chosen value
  35. $bap1 = $_POST['bap1'];
  36. $bappledging1 = $_POST['pledging1'];
  37. $bap2 = $_POST['bap1'];
  38. $bappledging2 = $_POST['pledging1'];
  39. $bap3 = $_POST['bap1'];
  40. $bappledging3 = $_POST['pledging1'];
  41. $bap4 = $_POST['bap1'];
  42. $bappledging4 = $_POST['pledging1'];
  43. $bap5 = $_POST['bap1'];
  44. $bappledging5 = $_POST['pledging1'];
  45. $bap6 = $_POST['bap1'];
  46. $bappledging6 = $_POST['pledging1'];
  47. $bap7 = $_POST['bap1'];
  48. $bappledging7 = $_POST['pledging1'];
  49. $bap8 = $_POST['bap1'];
  50. $bappledging8 = $_POST['pledging1'];
  51. $bap9 = $_POST['bap1'];
  52. $bappledging9 = $_POST['pledging1'];
  53. $bap10 = $_POST['bap1'];
  54. $bappledging10 = $_POST['pledging1'];
  55. // select the type from the database
  56. // database connection details (change to whatever you need)
  57. $HOST = 'localhost';
  58. $DATABASE = '';
  59. $USER = '';
  60. $PASSWORD = '';
  61. }
  62. // connect to database
  63. if(!$conn=mysql_connect('','','')) {
  64. echo("<li>Can't connect to $HOST as $USER");
  65. echo("<li>mysql Error: ".mysql_error());
  66. die;
  67. }
  68. // select database
  69. if (!mysql_select_db($DATABASE,$conn)) {
  70. echo("<li>We were unable to select database $DATABASE");
  71. die;
  72. }
  73. // if everything successful create query
  74. // this selects all rows where the type is the one you chose in the dropdown
  75. // * means that it will select all columns, ie name and type as i said above
  76. $bap1_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap1'";
  77. $bap2_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap2'";
  78. $bap3_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap3'";
  79. $bap4_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap4'";
  80. $bap5_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap5'";
  81. $bap6_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap6'";
  82. $bap7_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap7'";
  83. $bap8_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap8'";
  84. $bap9_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap9'";
  85. $bap10_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap10'";
  86. //product 1 sum
  87. $result = mysql_query($bap1_sql_query,$conn) or die('Invalid query: ' . mysql_error());
  88. $details = mysql_fetch_array($result);
  89. $bap1units = $bappledging1 = $_POST['pledging1'];
  90. $bap1mes = $details['mesurements'];
  91. $bapanswer1 = $bap1mes*$bap1units;
  92. ?>
i have only one row for lenth of thread perposes but all the php is there thanks in advance anyone
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 49
Reputation: uncle_smith is an unknown quantity at this point 
Solved Threads: 7
uncle_smith uncle_smith is offline Offline
Light Poster

Re: help with my scripot PLEASE!!! anyone?

 
0
  #2
Jan 29th, 2009
Originally Posted by gpittingale View Post
Can anyone please help here I have a form that i wish the user to select a product from a drop down box and then query it in a mysql then i would like to the user to input a number in the next field the press the submit button, then the form should do some simple maths and display it in the next field. now 3 things my code does not do 1/ the math and display it 2/the user input and the product i would like to remain after the form has been submitted 3/ also can anyone give some idea of how to get the form to calculate without a submitt button. here is my code:
  1. <form action="scdc_selfcompletion.php" method="post">
  2. <select name="bap10">
  3. <option selected="selected">Select One</option>
  4. <option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
  5. <option value="Re-Usable Bags">Re-Usable Bags</option>
  6. <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
  7. <option value="No Stand By">No Stand By</option>
  8. <option value="Use Energy Meter">Use Energy Meter</option>
  9. <option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
  10. <option value="Recycling">Recycling</option>
  11. <option value="Stop Junk Mail">Stop Junk Mail</option>
  12. </select>
  13. </td>
  14. <td width="19%">
  15. <input name="pledging" type="text" id="pledging" maxlength="5" />
  16. </td>
  17. <td>&nbsp;</td>
  18. <td>&nbsp;</td>
  19. </tr>
  20. <tr>
  21. <td colspan = '3'>Total Savings and Expenditure</td>
  22. <td>&nbsp;</td>
  23. <td>&nbsp;</td>
  24. </tr>
  25. </table>
  26. <input type="Submit" name="select" value="select">
  27. </form>
  28. <?php
  29. $select = $_POST['select'];
  30.  
  31. // if something has been chosen
  32. if (!empty($select)) {
  33.  
  34. // get the chosen value
  35. $bap1 = $_POST['bap1'];
  36. $bappledging1 = $_POST['pledging1'];
  37. $bap2 = $_POST['bap1'];
  38. $bappledging2 = $_POST['pledging1'];
  39. $bap3 = $_POST['bap1'];
  40. $bappledging3 = $_POST['pledging1'];
  41. $bap4 = $_POST['bap1'];
  42. $bappledging4 = $_POST['pledging1'];
  43. $bap5 = $_POST['bap1'];
  44. $bappledging5 = $_POST['pledging1'];
  45. $bap6 = $_POST['bap1'];
  46. $bappledging6 = $_POST['pledging1'];
  47. $bap7 = $_POST['bap1'];
  48. $bappledging7 = $_POST['pledging1'];
  49. $bap8 = $_POST['bap1'];
  50. $bappledging8 = $_POST['pledging1'];
  51. $bap9 = $_POST['bap1'];
  52. $bappledging9 = $_POST['pledging1'];
  53. $bap10 = $_POST['bap1'];
  54. $bappledging10 = $_POST['pledging1'];
  55. // select the type from the database
  56. // database connection details (change to whatever you need)
  57. $HOST = 'localhost';
  58. $DATABASE = '';
  59. $USER = '';
  60. $PASSWORD = '';
  61. }
  62. // connect to database
  63. if(!$conn=mysql_connect('','','')) {
  64. echo("<li>Can't connect to $HOST as $USER");
  65. echo("<li>mysql Error: ".mysql_error());
  66. die;
  67. }
  68. // select database
  69. if (!mysql_select_db($DATABASE,$conn)) {
  70. echo("<li>We were unable to select database $DATABASE");
  71. die;
  72. }
  73. // if everything successful create query
  74. // this selects all rows where the type is the one you chose in the dropdown
  75. // * means that it will select all columns, ie name and type as i said above
  76. $bap1_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap1'";
  77. $bap2_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap2'";
  78. $bap3_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap3'";
  79. $bap4_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap4'";
  80. $bap5_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap5'";
  81. $bap6_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap6'";
  82. $bap7_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap7'";
  83. $bap8_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap8'";
  84. $bap9_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap9'";
  85. $bap10_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap10'";
  86. //product 1 sum
  87. $result = mysql_query($bap1_sql_query,$conn) or die('Invalid query: ' . mysql_error());
  88. $details = mysql_fetch_array($result);
  89. $bap1units = $bappledging1 = $_POST['pledging1'];
  90. $bap1mes = $details['mesurements'];
  91. $bapanswer1 = $bap1mes*$bap1units;
  92. ?>
i have only one row for lenth of thread perposes but all the php is there thanks in advance anyone

First - what is the problem - what error do you get?

Second what is this: $select = $_POST['select']; ?

I am not sure this will work, I think you should refer to the select option as $_POST['bap10']

Third - why are you referring to values are $_POST['bap1'] when they belong to $_POST['bap1'];
$_POST['bap10']?

$4th - since select returnes only one value (the selected one), you dont need all these:

  1. // get the chosen value
  2. $bap1 = $_POST['bap1'];
  3. $bappledging1 = $_POST['pledging1'];
  4. $bap2 = $_POST['bap1'];
  5. $bappledging2 = $_POST['pledging1'];
  6. $bap3 = $_POST['bap1'];
  7. $bappledging3 = $_POST['pledging1'];
  8. $bap4 = $_POST['bap1'];
  9. $bappledging4 = $_POST['pledging1'];
  10. $bap5 = $_POST['bap1'];
  11. $bappledging5 = $_POST['pledging1'];
  12. $bap6 = $_POST['bap1'];
  13. $bappledging6 = $_POST['pledging1'];
  14. $bap7 = $_POST['bap1'];
  15. $bappledging7 = $_POST['pledging1'];
  16. $bap8 = $_POST['bap1'];
  17. $bappledging8 = $_POST['pledging1'];
  18. $bap9 = $_POST['bap1'];
  19. $bappledging9 = $_POST['pledging1'];
  20. $bap10 = $_POST['bap1'];
  21. $bappledging10 = $_POST['pledging1'];


Just use $_POST['bap10'] and $_POST['pledging1'] in your sql
that's all

One more thing: why are you using LIKE in your sql but then use exact values. Either use = instead of LIKE or use LIKE '%$val%'
Last edited by peter_budo; Jan 30th, 2009 at 2:22 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 31
Reputation: gpittingale is an unknown quantity at this point 
Solved Threads: 0
gpittingale gpittingale is offline Offline
Light Poster

Re: help with my scripot PLEASE!!! anyone?

 
0
  #3
Jan 29th, 2009
aaahhhrrrrr uncle smith i have heard all about you from Ardav he sais you are a legend and a better programmer, But thats a different story 1/ I get no error messages whatsoever i see what i should see but it just does not do anything?
2/$select = $_POST['select']; ? this is a variable for the submit button
3/Are you sying i should just use $_POST['bap1']; in my script and not turn them into variables, well at least that is what i think i am doing with them
4/ and the forth i will try cause i think i know what you mean!
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,396
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 170
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: help with my scripot PLEASE!!! anyone?

 
0
  #4
Jan 29th, 2009
grab a prewritten shopping cart script from hotscripts or somewhere, and \"borrow\" their method
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 49
Reputation: uncle_smith is an unknown quantity at this point 
Solved Threads: 7
uncle_smith uncle_smith is offline Offline
Light Poster

Re: help with my scripot PLEASE!!! anyone?

 
0
  #5
Jan 29th, 2009
Originally Posted by gpittingale View Post
aaahhhrrrrr uncle smith i have heard all about you from Ardav he sais you are a legend and a better programmer, But thats a different story 1/ I get no error messages whatsoever i see what i should see but it just does not do anything?
2/$select = $_POST['select']; ? this is a variable for the submit button
3/Are you sying i should just use $_POST['bap1']; in my script and not turn them into variables, well at least that is what i think i am doing with them
4/ and the forth i will try cause i think i know what you mean!
If you maned your 'select' group ['bap10'] then just $_POST['bap10'] and you will automatically get the value of selected item

You normally dont need the value of the submit button. I mean, the button is just used to submit the form and since there is usually only one submit button in the form, you dont need to extract its value.

And yes, you only need one sql in your script - it will be automatically populated with the value of selected item.
Last edited by uncle_smith; Jan 29th, 2009 at 12:24 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 31
Reputation: gpittingale is an unknown quantity at this point 
Solved Threads: 0
gpittingale gpittingale is offline Offline
Light Poster

Re: help with my scripot PLEASE!!! anyone?

 
0
  #6
Jan 29th, 2009
I have posted the whole script because i think i may be on the wrong track here i cant get it to work!! if you want to see the form as now to get a better ides of what i want to do go here
  1. <?php session_name('scdc');
  2. session_start();
  3. ?>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <title>Untitled Document</title>
  9. </head>
  10.  
  11. <body>
  12. <?php
  13. // select the type from the database
  14. // database connection details (change to whatever you need)
  15. $HOST = 'localhost';
  16. $DATABASE = 'k26bruc_cambsdata';
  17. $USER = ';
  18. $PASSWORD = ';
  19.  
  20. // connect to database
  21. if(!$conn=mysql_connect('localhost','','')) {
  22. echo("<li>Can't connect to $HOST as $USER");
  23. echo("<li>mysql Error: ".mysql_error());
  24. die;
  25. }
  26.  
  27. // select database
  28. if (!mysql_select_db($DATABASE,$conn)) {
  29. echo("<li>We were unable to select database $DATABASE");
  30. die;
  31. }
  32. ?>
  33. <p>Self Completion For : <?php echo(''.$_SESSION['ParishName'].''); ?>
  34. <form action="scdc_selfcompletion.php" method="post">
  35. <table width="800" border="1" cellspacing="2" cellpadding="3">
  36. <tr>
  37. <td colspan = '5'>Behaviour Alteration</td>
  38. </tr>
  39. <tr>
  40. <td>&nbsp;</td>
  41. <td>Product Type</td>
  42. <td>Number Pledging</td>
  43. <td>Energy Saved</td>
  44. <td>Investment By The Community</td>
  45. </tr>
  46. <tr>
  47. <td width="15%">Product 1</td>
  48. <td width="27%">
  49. <select name="bap1">
  50. <option selected="selected">Select One</option>
  51. <option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
  52. <option value="Re-Usable Bags">Re-Usable Bags</option>
  53. <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
  54. <option value="No Stand By">No Stand By</option>
  55. <option value="Use Energy Meter">Use Energy Meter</option>
  56. <option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
  57. <option value="Recycling">Recycling</option>
  58. <option value="Stop Junk Mail">Stop Junk Mail</option>
  59. </select>
  60. </td>
  61. <td width="19%">
  62. <input name="pledging1" type="text" id="pledging" maxlength="5" />
  63. </td>
  64. <td width="20%"><?php echo(''.$details['mesurements'].'')?></td>
  65. <td width="19%">&nbsp;</td>
  66. </tr>
  67. <tr>
  68. <td>Product 2</td>
  69. <td width="27%">
  70. <select name="bap2">
  71. <option selected="selected">Select One</option>
  72. <option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
  73. <option value="Re-Usable Bags">Re-Usable Bags</option>
  74. <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
  75. <option value="No Stand By">No Stand By</option>
  76. <option value="Use Energy Meter">Use Energy Meter</option>
  77. <option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
  78. <option value="Recycling">Recycling</option>
  79. <option value="Stop Junk Mail">Stop Junk Mail</option>
  80. </select>
  81. </td>
  82. <td width="19%">
  83. <input name="pledging2" type="text" id="pledging" maxlength="5" />
  84. </td>
  85. <td>&nbsp;</td>
  86. <td>&nbsp;</td>
  87. </tr>
  88. <tr>
  89. <td>Product 3</td>
  90. <td width="27%">
  91. <select name="bap3">
  92. <option selected="selected">Select One</option>
  93. <option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
  94. <option value="Re-Usable Bags">Re-Usable Bags</option>
  95. <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
  96. <option value="No Stand By">No Stand By</option>
  97. <option value="Use Energy Meter">Use Energy Meter</option>
  98. <option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
  99. <option value="Recycling">Recycling</option>
  100. <option value="Stop Junk Mail">Stop Junk Mail</option>
  101. </select>
  102. </td>
  103. <td width="19%">
  104. <input name="pledging3" type="text" id="pledging" maxlength="10" />
  105. </td>
  106. <td>&nbsp;</td>
  107. <td>&nbsp;</td>
  108. </tr>
  109. <tr>
  110. <td>Product 4</td>
  111. <td width="27%">
  112. <select name="bap4">
  113. <option selected="selected">Select One</option>
  114. <option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
  115. <option value="Re-Usable Bags">Re-Usable Bags</option>
  116. <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
  117. <option value="No Stand By">No Stand By</option>
  118. <option value="Use Energy Meter">Use Energy Meter</option>
  119. <option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
  120. <option value="Recycling">Recycling</option>
  121. <option value="Stop Junk Mail">Stop Junk Mail</option>
  122. </select>
  123. </td>
  124. <td width="19%">
  125. <input name="pledging4" type="text" id="pledging" maxlength="5" />
  126. </td>
  127. <td>&nbsp;</td>
  128. <td>&nbsp;</td>
  129. </tr>
  130. <tr>
  131. <td>Product 5</td>
  132. <td width="27%">
  133. <select name="bap5">
  134. <option selected="selected">Select One</option>
  135. <option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
  136. <option value="Re-Usable Bags">Re-Usable Bags</option>
  137. <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
  138. <option value="No Stand By">No Stand By</option>
  139. <option value="Use Energy Meter">Use Energy Meter</option>
  140. <option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
  141. <option value="Recycling">Recycling</option>
  142. <option value="Stop Junk Mail">Stop Junk Mail</option>
  143. </select>
  144. </td>
  145. <td width="19%">
  146. <input name="pledging5" type="text" id="pledging" maxlength="5" />
  147. </td>
  148. <td>&nbsp;</td>
  149. <td>&nbsp;</td>
  150. </tr>
  151. <tr>
  152. <td>Product 6</td>
  153. <td width="27%">
  154. <select name="bap6">
  155. <option selected="selected">Select One</option>
  156. <option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
  157. <option value="Re-Usable Bags">Re-Usable Bags</option>
  158. <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
  159. <option value="No Stand By">No Stand By</option>
  160. <option value="Use Energy Meter">Use Energy Meter</option>
  161. <option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
  162. <option value="Recycling">Recycling</option>
  163. <option value="Stop Junk Mail">Stop Junk Mail</option>
  164. </select>
  165. </td>
  166. <td width="19%">
  167. <input name="pledging6" type="text" id="pledging" maxlength="5" />
  168. </td>
  169. <td>&nbsp;</td>
  170. <td>&nbsp;</td>
  171. </tr>
  172. <tr>
  173. <td>Product 7</td>
  174. <td width="27%">
  175. <select name="bap7">
  176. <option selected="selected">Select One</option>
  177. <option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
  178. <option value="Re-Usable Bags">Re-Usable Bags</option>
  179. <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
  180. <option value="No Stand By">No Stand By</option>
  181. <option value="Use Energy Meter">Use Energy Meter</option>
  182. <option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
  183. <option value="Recycling">Recycling</option>
  184. <option value="Stop Junk Mail">Stop Junk Mail</option>
  185. </select>
  186. </td>
  187. <td width="19%">
  188. <input name="pledging7" type="text" id="pledging" maxlength="5" />
  189. </td>
  190. <td>&nbsp;</td>
  191. <td>&nbsp;</td>
  192. </tr>
  193. <tr>
  194. <td>Product 8</td>
  195. <td width="27%">
  196. <select name = "bap8">
  197. <option selected="selected">Select One</option>
  198. <option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
  199. <option value="Re-Usable Bags">Re-Usable Bags</option>
  200. <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
  201. <option value="No Stand By">No Stand By</option>
  202. <option value="Use Energy Meter">Use Energy Meter</option>
  203. <option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
  204. <option value="Recycling">Recycling</option>
  205. <option value="Stop Junk Mail">Stop Junk Mail</option>
  206. </select>
  207. </td>
  208. <td width="19%">
  209. <input name="pledging8" type="text" id="pledging" maxlength="5" />
  210. </td>
  211. <td>&nbsp;</td>
  212. <td>&nbsp;</td>
  213. </tr>
  214. <tr>
  215. <td>Product 9</td>
  216. <td width="27%">
  217. <select name="bap9">
  218. <option selected="selected">Select One</option>
  219. <option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
  220. <option value="Re-Usable Bags">Re-Usable Bags</option>
  221. <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
  222. <option value="No Stand By">No Stand By</option>
  223. <option value="Use Energy Meter">Use Energy Meter</option>
  224. <option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
  225. <option value="Recycling">Recycling</option>
  226. <option value="Stop Junk Mail">Stop Junk Mail</option>
  227. </select>
  228. </td>
  229. <td width="19%">
  230. <input name="pledging9" type="text" id="pledging" maxlength="5" />
  231. </td>
  232. <td>&nbsp;</td>
  233. <td>&nbsp;</td>
  234. </tr>
  235. <tr>
  236. <td>Product 10</td>
  237. <td width="27%">
  238. <select name="bap10">
  239. <option selected="selected">Select One</option>
  240. <option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
  241. <option value="Re-Usable Bags">Re-Usable Bags</option>
  242. <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
  243. <option value="No Stand By">No Stand By</option>
  244. <option value="Use Energy Meter">Use Energy Meter</option>
  245. <option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
  246. <option value="Recycling">Recycling</option>
  247. <option value="Stop Junk Mail">Stop Junk Mail</option>
  248. </select>
  249. </td>
  250. <td width="19%">
  251. <input name="pledging" type="text" id="pledging" maxlength="5" />
  252. </td>
  253. <td>&nbsp;</td>
  254. <td>&nbsp;</td>
  255. </tr>
  256. <tr>
  257. <td colspan = '3'>Total Savings and Expenditure</td>
  258. <td>&nbsp;</td>
  259. <td>&nbsp;</td>
  260. </tr>
  261. </table>
  262. <input type="Submit" name="select" value="select">
  263. </form>
  264. <?php
  265. // if something has been chosen
  266. if (!empty($select)) {
  267. // select the type from the database
  268. // database connection details (change to whatever you need)
  269. $HOST = 'localhost';
  270. $DATABASE = '';
  271. $USER = ';
  272. $PASSWORD = '';
  273. }
  274. // connect to database
  275. if(!$conn=mysql_connect('localhost','','')) {
  276. echo("<li>Can't connect to $HOST as $USER");
  277. echo("<li>mysql Error: ".mysql_error());
  278. die;
  279. }
  280. // select database
  281. if (!mysql_select_db($DATABASE,$conn)) {
  282. echo("<li>We were unable to select database $DATABASE");
  283. die;
  284. }
  285. // if everything successful create query
  286. // this selects all rows where the type is the one you chose in the dropdown
  287. // * means that it will select all columns, ie name and type as i said above
  288. $_POST['bap1'] = "SELECT * FROM Behaviour WHERE Product LIKE '$bap1'";
  289. $_POST['bap2'] = "SELECT * FROM Behaviour WHERE Product LIKE '$bap2'";
  290. $_POST['bap3'] = "SELECT * FROM Behaviour WHERE Product LIKE '$bap3'";
  291. $_POST['bap4'] = "SELECT * FROM Behaviour WHERE Product LIKE '$bap4'";
  292. $_POST['bap5'] = "SELECT * FROM Behaviour WHERE Product LIKE '$bap5'";
  293. $_POST['bap6'] = "SELECT * FROM Behaviour WHERE Product LIKE '$bap6'";
  294. $_POST['bap7'] = "SELECT * FROM Behaviour WHERE Product LIKE '$bap7'";
  295. $_POST['bap8'] = "SELECT * FROM Behaviour WHERE Product LIKE '$bap8'";
  296. $_POST['bap9'] = "SELECT * FROM Behaviour WHERE Product LIKE '$bap9'";
  297. $_POST['bap10']= "SELECT * FROM Behaviour WHERE Product LIKE '$bap10'";
  298. //product 1 sum
  299. $result = mysql_query($_POST['bap1'],$conn) or die('Invalid query: ' . mysql_error());
  300. $details = mysql_fetch_array($result);
  301. $bap1units = $bappledging1 = $_POST['pledging1'];
  302. $bap1mes = $details['mesurements'];
  303. $bapanswer1 = $bap1mes*$bap1units;
  304. ?>
  305. </body>
  306.  
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 2
Reputation: lifeofapirate is an unknown quantity at this point 
Solved Threads: 0
lifeofapirate lifeofapirate is offline Offline
Newbie Poster

Re: help with my scripot PLEASE!!! anyone?

 
0
  #7
Jan 30th, 2009
You folks are really helpful and knowledgeable. I wish I knew as much. I'm just a humble DreamWeaver user.

Don't laugh.

Well, okay you can. Where would I go to learn this stuff?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,088
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 137
ardav's Avatar
ardav ardav is online now Online
Veteran Poster

Re: help with my scripot PLEASE!!! anyone?

 
0
  #8
Jan 30th, 2009
gpit:

I noticed that your markup is repeated 10 times. pHp's for or while loop is made for this sort of stuff. I'd really suggest that you use a php loop to cut 250 lines to 25. It will be far more manageable - one change - all change.

  1. <p>Self Completion For : <?php echo(''.$_SESSION['ParishName'].''); ?>
  2. <form action="scdc_selfcompletion.php" method="post">
  3. <table width="800" border="1" cellspacing="2" cellpadding="3">
  4. <tr>
  5. <td colspan = '5'>Behaviour Alteration</td>
  6. </tr>
  7. <tr>
  8. <td>&nbsp;</td>
  9. <td>Product Type</td>
  10. <td>Number Pledging</td>
  11. <td>Energy Saved</td>
  12. <td>Investment By The Community</td>
  13. </tr>
  14.  
  15. <?php
  16. for($x = 1;$x <= 10,$x += 1){
  17. echo "\n<tr>\n\t<td>Product {$x}</td>\n\t<td width=\"27%\">\n\t<select name=\"bap{$x}\">\n\t\t<option selected=\"selected\">Select One</option>\n\t\t<option value=\"Energy Efficient Cooking\">Energy Efficient Cooking</option>\n\t\t<option value=\"Re-Usable Bags\">Re-Usable Bags</option>\n\t\t<option value=\"Keep Fridge/Freezer Ice Free\">Keep Fridge/Freezer Ice Free</option>\n\t\t<option value=\"No Stand By\">No Stand By</option>\n\t\t<option value=\"Use Energy Meter\">Use Energy Meter</option>\n\t\t<option value=\"Use Radio Other Than TV\">Use Radio Other Than TV</option>\n\t\t<option value=\"Recycling\">Recycling</option>\n\t\t<option value=\"Stop Junk Mail\">Stop Junk Mail</option>\n\t</select>\n\t</td>\n\t<td width=\"19%\">\n\t<input name=\"pledging\" type=\"text\" id=\"pledging\" maxlength=\"5\" />\n\t</td>\n\t<td>&nbsp;</td>\n\t<td>&nbsp;</td>\n</tr>\n";
  18. }
  19. ?>
  20. <tr>
  21. <td colspan = '3'>Total Savings and Expenditure</td>
  22. <td>&nbsp;</td>
  23. <td>&nbsp;</td>
  24. </tr>
  25. </table>
  26. <input type="Submit" name="select" value="select">
  27. </form>

That's your whole code for the form and table. If you need to add or subtract products, just change the $x <= 10 value.

I have to say, creating your own shopping cart is laudable, but terribly difficult. I wouldn't fancy it. There are loads of off-the-shelf solutions, as already suggested. You may be better off with those. If you're going to take online payment, I would definitely discourage you from "rolling your own". If you're just taking orders, fine.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: help with my scripot PLEASE!!! anyone?

 
1
  #9
Jan 30th, 2009
Originally Posted by lifeofapirate View Post
You folks are really helpful and knowledgeable. I wish I knew as much. I'm just a humble DreamWeaver user.

Don't laugh.

Well, okay you can. Where would I go to learn this stuff?
You would go home and reference the same resources I did:These are the things I typically reference when coding a web site.

So:
  1. sign up for a solid week of transcendental meditation to clear your mind of WYSIWYG web programming poison
  2. teach yourself to become proficient using the vim/vi text editor
  3. teach yourself the basics, the fundamentals, of relational database design and applications
  4. teach yourself the basics, the fundamentals, of programming
  5. teach yourself the basics, the fundamentals, of typesetting
  6. teach yourself the basics of whitespace and visual contrast
  7. teach yourself the difference between information and its presentation, and the difference between content management and presentation management
  8. teach yourself the basics of PHP
  9. teach yourself the basics of HTML 4.01
  10. teach yourself the basics of styles and CSS
  11. teach yourself the basics of accessing a MySQL DB using PHP
  12. design a simple, one-table personal schedule DB
  13. write a simple, dynamic web page that lets you add items to the DB, delete and change those items, and display them on the page
  14. access this page from Konqueror, Iceweasel, Firefox, Opera, Epiphany, IE and any other browsers you can find; make your page appear and function the same on all of them

When your single dynamic web page works satisfactorily and looks presentable, you'll be an apprentice LAMP web site programmer. This process should take you six to twelve months if you do nothing else.

Darn. It almost fit into 12 steps. Call it Fester's 14-Step Web WYSIWYG Recovery Program.
N
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


Views: 469 | Replies: 8
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC