Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> CHEBOX CHECKED MYSQL
diamondking
post
Post #1





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Chcę na stronie zrobić pole zainteresowania i ma być kilkanaście checboxów np. sport, muzyka, film...

Jak teraz pobrać zaznaczone checboxy, wysłac do bazy a po odświeżeniu pobrać je i zaznaczyć te, które były wybrane ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
diamondking
post
Post #2





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Chce mieć wszystkie dane w jednym polu ... znalazłem rozwiązanie - testuje je (IMG:style_emoticons/default/wink.gif)

  1. <?php
  2. include_once("config.php"); //include your db config file
  3. db_connect();
  4. extract($_POST);
  5. $zapytanie=mysql_query("select test from users");
  6. $ile=mysql_num_rows($zapytanie);
  7. $zawartosc=mysql_fetch_assoc($zapytanie);
  8. $wybrane=explode(',',$zawartosc['test']);
  9.  
  10. if(isset($submit) && $_POST['test']>= 1)
  11. {
  12. $checked = implode(",",$_POST['test']);
  13.  
  14. //update
  15. mysql_query("UPDATE users SET test='".$checked."' WHERE user_id='1'");
  16.  
  17.  
  18.  
  19. } else{
  20. //update
  21. mysql_query("UPDATE users SET test='' WHERE user_id='1'");
  22.  
  23. }
  24.  
  25. ?>
  26.  
  27. <form method="post" action="">
  28. <input type="checkbox" name="test[]" value="1" <?php if(in_array(1,$wybrane)){echo "checked";}?>><label>1</label><br>
  29. <input type="checkbox" name="test[]" value="2" <?php if(in_array(2,$wybrane)){echo "checked";}?>><label>2</label><br>
  30. <input type="checkbox" name="test[]" value="3" <?php if(in_array(3,$wybrane)){echo "checked";}?>><label>3</label><br>
  31. <input type="checkbox" name="test[]" value="4" <?php if(in_array(4,$wybrane)){echo "checked";}?>><label>4</label><br>
  32. <input type="checkbox" name="test[]" value="5" <?php if(in_array(5,$wybrane)){echo "checked";}?>><label>5</label><br>
  33. <input type="checkbox" name="test[]" value="6" <?php if(in_array(6,$wybrane)){echo "checked";}?>><label>6</label><br>
  34. <input type="checkbox" name="test[]" value="7" <?php if(in_array(7,$wybrane)){echo "checked";}?>><label>7</label><br>
  35. <input type="checkbox" name="test[]" value="8" <?php if(in_array(8,$wybrane)){echo "checked";}?>><label>8</label><br>
  36. <input type="submit" name="submit" value="submit">
  37. </form>
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: 18.10.2025 - 08:21