Condividi:        

Problemi Mysql e PHP

Problemi di HTML? Di PHP, ASP, .NET, JSP, Perl, SQL, JavaScript, Visual Basic..?
Vuoi realizzare programmi in C, C++, Java, Ruby o Smalltalk, e non sai da che parte cominciare?
Entra qui e troverai le risposte!

Moderatori: Anthony47, Triumph Of Steel, archimede

Problemi Mysql e PHP

Postdi Luciano_ » 08/10/10 16:33

sto lavorando sul mio sito ed al click su un collegamento il browser mi riporta la seguente dicitura:
Codice: Seleziona tutto
Following Error occured: (Type 256)
A fatal error occurred - Script terminated
Date: 08-10-2010 17:21:37

Error message: Query fatal error:
Query:UPDATE news1_news SET reads=reads+1 WHERE newsid='0'
Fehlermeldung: 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 'reads=reads+1 WHERE newsid='0'' at line 1

Script: C:\xampp\htdocs\baobab\news_engine\admin\enginelib\class.db.php ( on Line: 91)
Referer: http://localhost/...........index.php?ENGINEsessID=baa55eb482be41204954420092936d26
Client IP:
ho individuato il codice (lo riporto di seguito) che mi causa l'errore:
Codice: Seleziona tutto
{
    $newsid = $_GET['newsid'];
    $news = $db_sql->query_array("SELECT $news_table.*,$newscat_table.titel,$newscat_table.cat_image,$user_table.$username_table_column AS postname,$user_table.$useremail_table_column AS postmail, $user_table.$userhp_table_column AS posthp FROM $news_table
                           LEFT JOIN $newscat_table ON ($newscat_table.catid = $news_table.catid)
                        LEFT JOIN $user_table ON ($user_table.$userid_table_column = $news_table.userid)
                           WHERE newsid='$newsid' GROUP BY newsid");
    $news = stripslashes_array($news);
    $db_sql->sql_query("UPDATE $news_table SET reads=reads+1 WHERE newsid='$newsid'");
}
Potreste darmi una mano.
Grazie in anticipo e buon lavoro
Luciano
Luciano_
Newbie
 
Post: 4
Iscritto il: 08/10/10 16:24

Sponsor
 

Re: Problemi Mysql e PHP

Postdi Luciano_ » 10/10/10 10:13

Ragazzi ho risolto!
ho sostituito la riga
"UPDATE $news_table SET reads=reads+1 WHERE newsid='$newsid'"
con la seguente
"UPDATE `news1_news` SET `reads` = `reads` + 1 WHERE `newsid` = '1'"

Problema risolto :D
A presto
Luciano_
Newbie
 
Post: 4
Iscritto il: 08/10/10 16:24

Postdi archimede » 10/10/10 14:11

In pratica la tabella news1_news contiene SOLO il record con newsid=1? :eeh:

Se no, qualcosa di questo genere credo sia meglio (sintassi PHP da verificare):

$db_sql->sql_query("UPDATE ".$news_table." SET reads=reads+1 WHERE newsid=".$newsid);

Alessandro
archimede
Moderatore
 
Post: 2851
Iscritto il: 07/11/02 12:41
Località: Genova

Re: Problemi Mysql e PHP

Postdi Luciano_ » 11/10/10 09:58

Si nel database è presente una sola news che utilizzo per testare le funzionalità del sito ma ho inserito la stringa che mi hai suggerito ed il risultato è il seguente:

Following Error occured: (Type 256)
A fatal error occurred - Script terminated
Date: 11-10-2010 10:52:35

Error message: Query fatal error:
Query:UPDATE news1_news SET reads=reads+1 WHERE newsid=1
Fehlermeldung: 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 'reads=reads+1 WHERE newsid=1' at line 1

Script: C.....\class.db.php ( on Line: 90)
Referer: http://localhost.....
Client IP:


dov'è l'errore?
Grazie
Luciano
Luciano_
Newbie
 
Post: 4
Iscritto il: 08/10/10 16:24

Postdi archimede » 12/10/10 10:48

Luciano_ ha scritto:dov'è l'errore?
reads è un reserved word. Pessima idea: puoi risolvere con gli apici come hai fatto prima, ma è meglio se cambi nome al campo.

HTH.

Alessandro
archimede
Moderatore
 
Post: 2851
Iscritto il: 07/11/02 12:41
Località: Genova


Torna a Programmazione


Topic correlati a "Problemi Mysql e PHP":


Chi c’è in linea

Visitano il forum: Nessuno e 6 ospiti