Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: query jest błędne a jednak wyświetla że pomyślnie usunięto...
Forum PHP.pl > Forum > PHP
mathevs
Witam napisałem funkcje na usuwanie eventów funkcja działa poprawnie ale ... jesli w get id wpisze błędne id to i tak wywala że dodało pomyślnie ... nie wiem o co chodzi ..


Proszę o pomoc!


  1.  
  2.  
  3. $id = clearstr($_GET['id']);
  4.  
  5. $query = safe_sql("DELETE FROM ".$c['site'].".eventy WHERE id='".$id."'");
  6.  
  7. if(!$query) { echo'<script>alertify.error("Błąd w usuwaniu eventu!");</script>'; }
  8. else { echo'<script>alertify.success("Pomyślnie usunięto event!");</script>'; }
  9.  
  10.  
r4xz
google, google, google...

http://stackoverflow.com/questions/922398/...e-was-successfu
Cytat
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error

Cytat
PDO::exec() returns the number of rows that were modified or deleted by the SQL statement you issued. If no rows were affected, PDO::exec() returns 0


wniosek: skorzystaj z PDO

---edit---
no zawsze też można użyć jak piszą mysql_affected_rows, ale lepiej skorzystać z PDO
mathevs
Cytat(r4xz @ 13.04.2013, 10:13:53 ) *
google, google, google...

http://stackoverflow.com/questions/922398/...e-was-successfu



wniosek: skorzystaj z PDO

---edit---
no zawsze też można użyć jak piszą mysql_affected_rows, ale lepiej skorzystać z PDO



nie da się zrobić tego jakoś prosciej bo PDO nie obczajam .. :/
r4xz
http://pl1.php.net/mysql_affected_rows
  1. <?php
  2. $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
  3. if (!$link) {
  4. die('Could not connect: ' . mysql_error());
  5. }
  6.  
  7. /* this should return the correct numbers of deleted records */
  8. mysql_query('DELETE FROM mytable WHERE id < 10');
  9. printf("Records deleted: %d\n", mysql_affected_rows());
  10.  
  11. /* with a where clause that is never true, it should return 0 */
  12. mysql_query('DELETE FROM mytable WHERE 0');
  13. printf("Records deleted: %d\n", mysql_affected_rows());
  14. ?>


czytaj przykłady i komentarze 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.