Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP] Wysłanie formularza
Forum PHP.pl > Forum > Przedszkole
falent
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. ?>
krzywy36
myślisz, że komuś się będzie chciało analizować Twój kod skoro nie napisałeś nawet w czym problem?
falent
przepraszam, jestem tak zmęczony, że już nie myślę sad.gif Po wysłaniu Submit pojawia się pusta strona w index.php
krzywy36
pousuwaj małpy z funkcji mysql a do mysql_query pododawaj 'or die(mysql_error());' i pokaż co wywala.
falent
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
krzywy36
musisz nadać polom formularza atrybut name wink.gif
falent
dzięki smile.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.