Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP] Wysłanie formularza
falent
post 5.07.2012, 19:43:50
Post #1





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 3.06.2012

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


Męczę się już z tym parę godzin sad.gif Gdzie robię błąd?

choice.php

  1. <html>
  2. <head>
  3. </head>
  4.  
  5. <body>
  6. <form id="choice" action="index.php" method="post">
  7. <script type = "text/javascript">
  8. function NewList(selObj,newObj,addObj) {
  9. var selElem = document.getElementById(selObj);
  10. var selIndex = selElem.selectedIndex;
  11. var newElem = document.getElementById(newObj);
  12. var tmp = '';
  13. newElem.options.length = 0;
  14.  
  15. for (var i=0; i<selElem.options.length; i++) {
  16. tmp = selElem.options[i].value;
  17. if (i != selIndex) { newElem.options[newElem.options.length] = new Option(tmp,tmp); }
  18. }
  19. }
  20.  
  21. function submit() {
  22. var message = "Your selections were:- ";
  23. if ((document.getElementById("SBox0").value != "Select A Fruit") && (document.getElementById("SBox1").value != "Select A Fruit") && (document.getElementById("SBox2").value != "Select A Fruit") ) {
  24. message += document.getElementById("Sbox0").value + " ";
  25. message += document.getElementById("Sbox1").value + " ";
  26. message += document.getElementById("Sbox2").value;
  27. }
  28. else {message = "You must make a selection from all three lists"}
  29. alert (message);
  30. }
  31. </script>
  32.  
  33. FIRST CHOICE <select id="SBox0" onchange="NewList('SBox0','SBox1','AddedOptions')">
  34. <option value ="Select A Fruit">Select A Fruit </option>
  35. <option value="Apple">Apple</option>
  36. <option value="Orange">Orange</option>
  37. <option value="Mango">Mango</option>
  38. </select>
  39.  
  40. SECOND CHOICE <select id="SBox1" onchange="NewList('SBox1','SBox2','')">
  41. <option value=""></option>
  42. </select>
  43.  
  44. THIRD CHOICE <select id="SBox2">
  45. <option value=""></option>
  46. </select>
  47.  
  48. &nbsp &nbsp <input type = "submit" value = "Submit" onclick = "submit()">
  49. </body>
  50. </html>


index.php

  1. <?php
  2.  
  3. $SBox0 = $_POST['SBox0'];
  4. $SBox1 = $_POST['SBox1'];
  5. $SBox2 = $_POST['SBox2'];
  6.  
  7.  
  8. if($SBox0 and $SBox1 and $SBox2 ) {
  9.  
  10.  
  11. $connection = @mysql_connect('****', '********', '*********')
  12. or die('error');
  13. mysql_query("SET NAMES 'utf8'");
  14. $db = @mysql_select_db('*****_choice', $connection)
  15. or die('error');
  16.  
  17.  
  18. $ins = @mysql_query("INSERT INTO choice SET SBox0='$SBox0', SBox1='$SBox1', Sbox2='$SBox2'");
  19.  
  20. if($ins) echo "Thanks";
  21. else echo "<strong>Sorry but we have problem</strong>";
  22.  
  23. mysql_close($connection);
  24. }
  25. ?>
Go to the top of the page
+Quote Post
krzywy36
post 5.07.2012, 19:46:15
Post #2





Grupa: Zarejestrowani
Postów: 370
Pomógł: 43
Dołączył: 1.12.2007
Skąd: Kędzierzyn Koźle

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


myślisz, że komuś się będzie chciało analizować Twój kod skoro nie napisałeś nawet w czym problem?


--------------------
pretty as a shit.
Go to the top of the page
+Quote Post
falent
post 5.07.2012, 19:49:13
Post #3





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 3.06.2012

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


przepraszam, jestem tak zmęczony, że już nie myślę sad.gif Po wysłaniu Submit pojawia się pusta strona w index.php
Go to the top of the page
+Quote Post
krzywy36
post 5.07.2012, 19:51:00
Post #4





Grupa: Zarejestrowani
Postów: 370
Pomógł: 43
Dołączył: 1.12.2007
Skąd: Kędzierzyn Koźle

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


pousuwaj małpy z funkcji mysql a do mysql_query pododawaj 'or die(mysql_error());' i pokaż co wywala.


--------------------
pretty as a shit.
Go to the top of the page
+Quote Post
falent
post 5.07.2012, 19:55:03
Post #5





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 3.06.2012

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


usunąłem i mam pustą stronę.

Zrobiłem formularz i wysłałem do index.php zmiennę SBox0, SBox1, SBox2

i zostały dodane do bazy. Coś jest nie tak z kodem choice.php
Go to the top of the page
+Quote Post
krzywy36
post 5.07.2012, 19:59:37
Post #6





Grupa: Zarejestrowani
Postów: 370
Pomógł: 43
Dołączył: 1.12.2007
Skąd: Kędzierzyn Koźle

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


musisz nadać polom formularza atrybut name wink.gif


--------------------
pretty as a shit.
Go to the top of the page
+Quote Post
falent
post 5.07.2012, 20:18:03
Post #7





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 3.06.2012

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


dzięki smile.gif
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 24.06.2025 - 01:56