Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Maly problem z wstawianiem zmiennych
eXido
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 20.04.2006

Ostrzeżenie: (0%)
-----


Witam,

Ponizej jest kod na którym pracuje, nic wielkiego, uzytkownik wpisuje pare rzeczy które php potem przekazje MySQLowi:

  1. <html>
  2. <head><title>Add a Hirer!</title>
  3. </head>
  4. <body background="img19.gif">
  5.  
  6. <center>
  7. <p1><B>Add a New Hirer to the Village Hall Booking System!</B></p1>
  8. </center>
  9.  
  10.  
  11. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  12.  
  13. <br><table><tr><td width="200">
  14.  
  15. Title</td><td width="200"><select name="title">
  16. <option>Choose
  17. <option>Doctor
  18. <option>Father
  19. <option>Master
  20. <option>Miss
  21. <option>Mr
  22. <option>Mrs
  23. <option>Professor
  24. <option>Sister
  25. </select>
  26.  
  27. </td><td width="200"><b>Further Details</b></td></tr>
  28.  
  29. <tr><td width="200">
  30.  
  31. Surname</td><td width="150"><input type="text" name="surname"><br></td><td width="200">Time of Booking:</td>
  32. <td width="200"><select name="Time">
  33. <option selected>Choose
  34. <Option>Morning
  35. <Option>Afternoon
  36. <Option>Evening
  37. <Option>Evening Extension
  38. </select>
  39. </td></tr><tr><td width="200">Forename</td><td width="200"><input type="text" name="forename"></td>
  40. <td width="200">Type of Booking:</td><td width="200"><select name="Type">
  41. <option selected>Choose
  42. <option>Chess Club
  43. <option>Cubs & Scouts
  44. <option>Golden Wedding Anniversary
  45. <option>Guides & Brownies
  46. <option>Line Dancing
  47. <option>Play Group
  48. <option>Silver Wedding Anniversary
  49. <option>Women's Institute
  50. <option>18th Birthday Party
  51. <option>Other
  52. </select>
  53. </td></tr><tr><td width="200">Street Number</td><td width="200"><input type="text" name="street_number"></td>
  54. <td width="200">Date:</td><td width="200">
  55.  
  56. <select name="DateNumber">
  57. <option selected>1
  58. <option>2
  59. <option>3
  60. <option>4
  61. <option>5
  62. <option>6
  63. <option>7
  64. <option>8
  65. <option>9
  66. <option>10
  67. <option>11
  68. <option>12
  69. <option>13
  70. <option>14
  71. <option>15
  72. <option>16
  73. <option>17
  74. <option>18
  75. <option>19
  76. <option>20
  77. <option>21
  78. <option>22
  79. <option>23
  80. <option>24
  81. <option>25
  82. <option>26
  83. <option>27
  84. <option>28
  85. <option>29
  86. <option>30
  87. <option>31
  88. <option>32
  89. </select>
  90.  
  91. <select name="DateMonth">
  92. <option selected>January
  93. <option>February
  94. <option>March
  95. <option>April
  96. <option>May
  97. <option>June
  98. <option>July
  99. <option>August
  100. <option>September
  101. <option>October
  102. <option>November
  103. <option>December
  104. </select>
  105.  
  106. <select name="DateYear">
  107. <option selected>2005
  108. <option>2006
  109. <option>2007
  110. </select>
  111.  
  112. </td></tr><tr><td width="200">Street Name</td><td width="200"><input type="text" name="street_name"></td>
  113. <td width="200">Day Of Week:</td><td width="200"><select name="Day_of_week">
  114. <option selected>Choose
  115. <option>Monday
  116. <option>Tuesday
  117. <option>Wednesday
  118. <option>Thursday
  119. <option>Friday
  120. <option>Saturday
  121. <option>Sunday
  122. </select>
  123. </td></tr><tr><td width="200">Town/City</td><td width="200"><input type="text" name="town_city"></td>
  124. <td width="200">Regular Customer:</td><td width="200"><select name="Regular">
  125. <option selected>Choose
  126. <option>Yes
  127. <option>No
  128. </select>
  129. </td></tr><tr><td width="200">County</td><td width="200"><input type="text" name="county"></td>
  130. <td width="200">Paid:</td><td width="200"><select name="Paid">
  131. <option selected>Choose
  132. <option>Yes
  133. <option>No
  134. </select>
  135. </td></tr><tr><td width="200">Post Code</td><td width="200"><input type="text" name="PostCode">
  136. </td></tr><tr><td width="200">Home Tel. No.</td><td width="200"><input type="text" name="home_tel">
  137. </td></tr><tr><td width="200">Mobile Tel. No.</td><td width="200"><input type="text" name="mobile_tel">
  138. </td></tr><tr><td width="200">Email</td><td width="200"><input type="text" name="email">
  139. </td></tr> 
  140.  
  141.  
  142. </table>
  143.  
  144. <br><br><input type="submit" value="Submit"><br><br>
  145. </form>
  146. <font color="orange"><font size="4"><B>
  147. <?php
  148.  
  149. $Time = $_REQUEST['Time'];
  150. $Price = $_REQUEST['Price'];
  151. $Regular = $_REQUEST['Regular'];
  152. $Paid = $_REQUEST['Paid'];
  153. $Type = $_REQUEST['Type'];
  154. $Day_of_week = $_REQUEST['Day_of_week'];
  155.  
  156.  
  157. if ($Type == 'Golden Wedding Anniversary' OR $Type == 'Silver Wedding Anniversary' OR $Type == '18th Birthday Party' AND $Day_of_week == 'Friday' OR $Day_of_week == 'Saturday' AND $Time == 'Evening') {
  158. $Price="10.00";
  159. echo "Your booking qualifies for our special rate of 10.00 pounds including the e
    vening extension!"
    ;
  160.  
  161. }
  162.  
  163.  
  164. elseif ($Time == 'Morning') {
  165. $Price="12.00";
  166. echo "The price is 12.00 pounds.";
  167.  
  168. }
  169.  
  170. elseif ($Time == 'Afternoon') {
  171. $Price="12.00";
  172. echo "The price is 12.00 pounds.";
  173.  
  174. }
  175.  
  176. elseif ($Time == 'Evening') {
  177. $Price="15.00";
  178. echo "The price is 15.00 pounds.";
  179.  
  180. }
  181.  
  182. elseif ($Time == 'Evening Extension') {
  183. $Price="5.00";
  184. echo "The price is 5.00 pounds.";
  185.  
  186. }
  187.  
  188.  
  189.  
  190. else {
  191.  
  192. echo "The price will be quoted based on your selection.";
  193.  
  194. }
  195.  
  196.  
  197. if ($Regular == 'Yes') {
  198. $Regular="Yes";
  199. }
  200. else {
  201. $Regular="No";
  202. }
  203.  
  204. if ($Paid == 'Yes') {
  205. $Paid="Yes";
  206. }
  207. else {
  208. $Paid="No";
  209. }
  210.  
  211.  
  212. ?>
  213. <br>
  214. <?php
  215.  
  216. $dbcnx = @mysql_connect('localhost', 'anglopol_admin', 'pass');
  217. if (!$dbcnx) {
  218. exit('<p>Unable to connect to the database server at this time.</p>');
  219. }
  220.  
  221. if (!@mysql_select_db('anglopol_VillageHall')) {
  222. exit('<p>Unable to locate the Village Hall database at this time.</p>');
  223. }
  224.  
  225.  
  226. if (isset($_POST['title'])) {
  227.  
  228.  
  229. $title = $_POST['title'];
  230. $surname = $_POST['surname'];
  231. $forename = $_POST['forename'];
  232. $street_number = $_POST['street_number'];
  233. $street_name = $_POST['street_name'];
  234. $town_city = $_POST['town_city'];
  235. $county = $_POST['county'];
  236. $PostCode = $_POST['PostCode'];
  237. $Home_Tel = $_POST['home_tel'];
  238. $Mobile_Tel = $_POST['mobile_tel'];
  239. $email = $_POST['email'];
  240. $Time = $_POST['Time'];
  241. $Type = $_POST['Type'];
  242. $DateNumber = $_POST['DateNumber'];
  243. $DateMonth = $_POST['DateMonth'];
  244. $DateYear = $_POST['DateYear'];
  245. $Price = $_POST['Price'];
  246. $Regular = $_POST['Regular'];
  247. $Paid = $_POST['Paid'];
  248.  
  249. $sql = "INSERT INTO Hirer SET
  250. title='$title',
  251. surname='$surname',
  252. forename='$forename',
  253. street_number='$street_number',
  254. street_name='$street_name',
  255. town_city='$town_city',
  256. county='$county',
  257. PostCode='$PostCode',
  258. Home_Tel='$Home_Tel',
  259. Mobile_Tel='$Mobile_Tel',
  260. Email='$email'
  261. Time='$Time',
  262. Type='$Type',
  263. DateNumber='$DateNumber',
  264. DateMonth='$DateMonth',
  265. DateYear='$DateYear',
  266. Day_of_week='$Day_of_week',
  267. Price='$Price',
  268. Regular='$Regular',
  269. Paid='$Paid'";
  270.  
  271. if (@mysql_query($sql)) {
  272.  
  273. echo '<p>Your Hirer & Booking Details have been added.</p>';
  274. } else {
  275. echo '<p>Error submitting hirer details: ' .
  276. mysql_error() . '</p>';
  277. }
  278. }
  279.  
  280. $HirerID = mysql_insert_id();
  281. ?>
  282.  
  283.  
  284. <br><a href="mainpage.php"> Back to Main Page</a>
  285.  
  286.  
  287. </body>
  288. </html>


Ta stronka juz mi wczesniej dzialala w 100%, tyle ze potem dodalem pare dodatkowych informacji które maja znalezc sie w bazie danych, wszystkie te po $_POST['Email'].
I teraz problem, przestalo dzialac i wyrzuca mi taki blad:

  1. <?php
  2.  
  3. Error submitting hirer details: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Time='Choose' Type='Choose' DateNumber='1' DateMonth='January' DateYear=' at line 13
  4.  
  5. ?>


Widze ze cos jest nie tak z tymi nowymi informacjami które dodalem ale siedzie juz nad tym od wczoraj i przegladam caly kod nie widzac co jest nie tak.
Bylbym naprawde wdzieczny gdyby którys ze znawców mógl pokazac w czym problem (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

Pozdrawiam.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




Cytat
A jak taki input by wygladal, zeby bylo tak jak piszesz w formacie rrrr-mm-dd?
Jest to najwyzkleszy w swiecie input type="text" do ktorego mozesz wpisac dowolny text. ty tylko potem ten tekst musisz zwalidowac, czy jest odpowiedniego formatu. Jak pisalem mnostwo tego bylo na forum, na sieci. wystraczy przejrzec.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 3.10.2025 - 05:34