Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][SQL][MySQL]prepare & mysqli
eminiasty
post
Post #1





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


Czy poniższy kod da się jakoś uprościć i czy w ogóle jest poprawny?
  1. $value ='1';
  2.  
  3. $stmt = $link->prepare("SELECT id FROM " . $db_prefix . "test WHERE id = ?");
  4.  
  5.  
  6. $stmt->bind_param('i', $value);
  7.  
  8. if($stmt->execute()) {
  9.  
  10. $result = $stmt->get_result();
  11.  
  12. while ($row = $result->fetch_assoc()) {
  13.  
  14. echo $row['id'];
  15.  
  16. }
  17.  
  18. }
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
eminiasty
post
Post #2





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


Odnośnie $active, pole w bazie jest typu tinyint(i)
W form jest:
  1. <div class="form-group">
  2. <label for="ActiveModule">Aktywny</label>
  3. <div class="checkbox">
  4. <label><input name="active" type="radio" value="1" id='ActiveModule' required>TAK</label>
  5. <label><input name="active" type="radio" value="0" checked>NIE</label>
  6. </div>
  7. </div>

Czy da sie tu użyć bindowania jako b wgole? Pytam dlatego, że do bazy zwraca zawsze 0?

Ten post edytował eminiasty 19.08.2017, 14:02:40
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: 12.10.2025 - 07:31