Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11

Discussione: Errore di sintassi

  1. #1

    Errore di sintassi

    Ciao a tutti...

    Sto leggermente sclerando e mi girano gli occhi

    Mi esce questo errore quando cerco di UPDATARE una NEWS (quando la inserisco nessun problema):

    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 '' at line 1

    Questa è la query...

    function UpdateNews($data, $titolo, $testo, $id)
    {
    $strSql = "Update news SET data='".$data."', titolo='".$titolo."', testo='".$testo."'";
    $strSql = $strSql . " WHERE id = " . $id;
    return $strSql;
    }

    Aspetto buone nuove... intanto ricontrollo per la X volta

  2. #2
    Che cosa restituisce questo codice:

    Codice PHP:
    var_dump($strSql); 

  3. #3
    Mo' faccio la figura della deficente...

    Questo var_dump... non devo metterlo nel dbquery... ma nel file che mi gestisce la news, cioè managenews.php, giusto?

    <?php
    include("../util/dbconn.php");
    include("../util/dbquery.php");

    session_start();
    if (!readCookie('admin', $_SESSION['userid']))
    {
    header("location: index.php");
    }

    $dbConn = OpenConn();

    $submit = $_POST['_submit'];

    $id = $_POST['id'];
    $_data = $_POST['_data'];
    $_titolo = $_POST['_titolo'];
    $_testo = $_POST['_testo'];

    var_dump($strSql);

    //inserimento prodotto

    switch ($submit)
    {
    case "Insert":
    $sSql = InsertNews($_data, $_titolo, $_testo);
    break;
    case "Update":
    $sSql = UpdateNews($_data, $_titolo, $_testo, $_id);
    break;
    }

    $result = mysql_query($sSql, $dbConn) or die('
    '. mysql_error() . '
    ');

    if ($submit == "Insert")
    {
    $sSql = GetLastNews();
    $result = mysql_query($sSql, $dbConn);
    $row = mysql_fetch_array($result);
    $id = $row['id'];
    mysql_free_result($result);
    }

    header("location: news.php?id=". $id);

    CloseConn($dbConn);

    ?>

    Facendo così e cliccando su update... esce fuori...

    NULL
    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 '' at line 1

    ... sicuramente è sbagliato... boh... non lo so...

  4. #4
    Hai posizionato male il var_dump.
    Lo devi inserire dopo che la variabile $sSql viene valorizzata.

    Codice PHP:
    //inserimento prodotto

    switch ($submit)
    {
    case 
    "Insert":
    $sSql InsertNews($_data$_titolo$_testo);
    break;
    case 
    "Update":
    $sSql UpdateNews($_data$_titolo$_testo$_id);
    break;
    }

    var_dump($sSql );     // Il var_dump va messo qua. 

    Oppure

    Lo devi mettere nella funzione UpdateNews

    Codice PHP:
    function UpdateNews($data$titolo$testo$id)
    {
    $strSql "Update news SET data='".$data."', titolo='".$titolo."', testo='".$testo."'";
    $strSql $strSql " WHERE id = " $id;
    var_dump($strSql );  
    return 
    $strSql;


  5. #5
    Grazie

    Dunque l'ho posizionato nel dbquery... ho caricato... ho refreshato...

    Ed esce...

    string(139) "Update news SET data='ddddddddddddddd', titolo='ddddddddddddddddddddddd', testo='ccccccccccccccccccccccddddddddddddddddddddd dd' WHERE id = "
    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 '' at line 1


    :master:

    Messo invece nel managenews.php e, ovviamente, tolto dal dbquery esce...

    string(130) "Update news SET data='ddddddddddddddd', titolo='ddddddddddddddddddddddd', testo='dddddddddddddddddxxxxxxxxxxxxxxxxxxx' WHERE id = "
    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 '' at line 1

    Prima 139 poi 130

  6. #6
    Manca la valorizzazione del campo id nella clausola WHERE.

    Che cosa restituisce questo codice?

    Codice PHP:
    var_dump($id); 

  7. #7
    Se lo metto come

    function UpdateNews($data, $titolo, $testo, $id)
    {
    $strSql = "Update news SET data='".$data."', titolo='".$titolo."', testo='".$testo."'";
    $strSql = $strSql . " WHERE id = " . $id;
    var_dump($id);
    return $strSql;
    }

    Esce...

    NULL
    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 '' at line 1

  8. #8
    Il problem è piuttosto chiaro, stai passando un NULL come $id e questo "genera" una query SQL NON valida.

    Controlla il tuo codice e verifica per quale motivo richiami la funzione UpdateNews() passando un $id non valido.

  9. #9
    Mmmm... togliendo $id dalla function (che alla fine non mi serve)...

    Mi esce sempre l'errore con NULL...

    Il fatto è che ho già usato questo dbquery per un altro lavoro... e lì funziona alla perfezione... non genera nessun errore quando voglio updatare qualche news :master:

  10. #10
    Codice PHP:
    $id $_POST['id'];
    $_data $_POST['_data'];
    $_titolo $_POST['_titolo'];
    $_testo $_POST['_testo']; 
    scusa , ma la variabile id ... non era _id ??? ..
    in quel caso dovresti fare $id = $_POST['_id']; ..

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.