Visualizzazione dei risultati da 1 a 9 su 9

Discussione: SQL error

  1. #1

    SQL error

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like = 1, dislike = 0 WHERE stato = 1' at line 1

    Ciao ho questo errore in questa query e la cosa mi sembra strana perchè non mi sembra di aver fatto errori:

    Codice PHP:
    $querys mysql_query("UPDATE Stati_giud SET $tab = 1, $ot = 0 WHERE stato = $idpost") or die(mysql_error()); 
    Questa query insieme a un'altra è contenuta in un else

    Codice PHP:
    $sql mysql_query("UPDATE Stati SET ".$tab."s = '1', ".$ot."s = '0' WHERE id='$idpost'") or die(mysql_error());
    $querys mysql_query("UPDATE Stati_giud SET $tab = 1, $ot = 0 WHERE stato = $idpost") or die(mysql_error()); 
    La prima funziona,ma la seconda no...come posso risolvere?

  2. #2
    You placed variables like that in queries Select xyz from abc wheer {$variable}

  3. #3
    Thanks for the reply...I have tried to place variables {$tab} , {$ot}, ecc.
    but I have the same error

  4. #4
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,505
    Tu scrivi così
    Codice PHP:
    $sql mysql_query("UPDATE Stati SET ".$tab."s = '1', ".$ot."s = '0' WHERE id='$idpost'") or die(mysql_error()); 
    ma se i campi contenuti in $tab e $tot sono definiti come int o altro formato numerico, devi togliere gli apici attorno a 1 e 0, altrimenti saranno visti come stringhe e il tipo non coinciderà con quello richiesto dai campi.

  5. #5
    Ho tolto gli apici,ma mi da lo stesso errore e nella query dove mi da l'errore gli apici intorno ai numeri non c'erano già

  6. #6
    Utente di HTML.it
    Registrato dal
    May 2012
    Messaggi
    1,453
    Forse ti sei dimenticato di concatenare la s come la query sopra per i campi...?


    Eseguita dal phpmyadmin funziona? Ovviamente sostituendo le variabili con valori di esempio

  7. #7
    Allora:

    Codice PHP:
    $sql mysql_query("UPDATE Stati SET ".$tab."s = 1, ".$ot."s = 0 WHERE id = $idpost") or die(mysql_error());
    $query mysql_query("UPDATE Stati_giud SET $tab = 1, $ot = 0 WHERE stato = $idpost") or die(mysql_error()); 
    L'errore me lo da in questa query:
    Codice PHP:
    $query mysql_query("UPDATE Stati_giud SET $tab = 1, $ot = 0 WHERE stato = $idpost") or die(mysql_error()); 
    Nono nella tabella dove mi da l'errore non c'è la s finale nei campi
    Ho provato anche io a togliere le variabili e a scrivere dei valori,ma l'errore è sempre quello che ho scritto al primo post

  8. #8
    Utente di HTML.it L'avatar di Enoa
    Registrato dal
    Jul 2005
    Messaggi
    573
    "like" è una parola riservata
    http://dev.mysql.com/doc/refman/5.5/...ved-words.html
    (nel caso specifico una funzione per il confronto delle stringhe http://dev.mysql.com/doc/refman/4.1/...functions.html)

    O cambi il nome del campo o usi i backticks -> `like` (ALT+apostrofo, tastiera querty su linux)

  9. #9
    Grazie infinite stavo impazzendo!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.