[php-mysql] fout in de query

Gestart doorMarjolein37 reacties107 weergaven

38 berichten · pagina 1 van 3

Marjolein

Lid · Topicstarter

Berichten
15.446
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wie kan mij helpen hiermee?
Foutmelding:
Er is een fout opgetreden in de query:
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 1 at line 1


dit is een deel van de code waar het om gaat:

[COLOR= #0000BB]<?php
$toevoegquery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO aankondigingen (poster, titel, bericht, datum) 
                        VALUES ("[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]poster[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]", "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]titel[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]", "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]", NOW())"[/COLOR][COLOR= #007700]);[/COLOR] 

                        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$toevoegquery[/COLOR][COLOR= #007700]))
                            {[/COLOR]  
                            [COLOR= #0000BB]$usql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT id, naam, email, bevestigd FROM abonnement WHERE bevestigd=1"[/COLOR][COLOR= #007700]);[/COLOR]
                            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$usql[/COLOR][COLOR= #007700]))
                                {[/COLOR]
                                [URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$ufetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$usql[/COLOR][COLOR= #007700]))
                                    {[/COLOR]
                                   [COLOR= #FF8000]//[knip > staan dingen zoals $headers, $bericht enz voor het verzenden van een mail naar verschillende adressen die in de datbase staan][/COLOR]
                           
                                      [COLOR= #0000BB]$mail[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mail"]mail[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$ufetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]],[/COLOR][COLOR= #DD0000]"Nieuwe aankondiging "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$sitenaam[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$bericht[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$headers[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"From: "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$sitenaam[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]" <"[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$sitemail[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]">"[/COLOR][COLOR= #007700]);
                                    }[/COLOR]
                                    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$mail[/COLOR] [COLOR= #007700]==[/COLOR] TRUE[COLOR= #007700]) 
                                    {[/COLOR]
                                    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<div style="width: 400px; margin: 0 auto; text-align: center;">
                                    De aankondiging is geplaatst op de homepagina en de abonnement mailtjes zijn verstuurd</div>[/COLOR][COLOR= #007700];

                                    }
                                }
                        }[/COLOR]
                        [URL="http://www.php.net/else"]else[/URL]
                        [COLOR= #007700]{[/COLOR]
                            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br />Er is een fout opgetreden in de query: <br />[/COLOR][COLOR= #007700];[/COLOR]
                            [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700](); 
                        }[/COLOR]
?>


De gegevens worden wel toegevoegd in de database maar de rest voert het script niet uit.
En het vreemde is, ik heb exact dezelfde code op een andere host staan en daar werkt die wel correct, dus ik snap er helemaal niks van...
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
$usql = mysql_query ("SELECT id, naam, email, bevestigd FROM abonnement WHERE bevestigd=1");

die bevestigd=1 , die 1 moet tussen haakjes.

$usql = mysql_query ("SELECT id, naam, email, bevestigd FROM abonnement WHERE bevestigd=1");

toevoeging op 8 april 2012, 00:38:33:
Nu moet jij mij helpen, kijk PB hypocrite
0
Marjolein

Lid · Topicstarter

Berichten
15.446
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
die 1 tussen haakjes helpt niet, dat heb ik natuurlijk zelf allang geprobeerd. Ook als ik die query zonder de WHERE uitvoer krijg ik nog steeds dezelfde fout.
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
mysql_query("INSERT INTO aankondigingen (poster, titel, bericht, datum) 
                        VALUES (" . $_POST[poster] . ", " . $_POST[titel] . ", " . $_POST[bericht] . ", NOW())");


Plaats je daar eergens een 1 in

Anders

$usql = mysql_query ("SELECT `id`, `naam`, `email`, `bevestigd` FROM `abonnement` WHERE `bevestigd` = 1 ");
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$toevoegquery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO aankondigingen (poster, titel, bericht, datum)
                        VALUES ("[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]poster[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]", "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]titel[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]", "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]", NOW())"[/COLOR][COLOR= #007700]);[/COLOR]

                        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$toevoegquery[/COLOR][COLOR= #007700]))
                            {[/COLOR]  
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]tot nu toe gaat het goed :D[/COLOR][COLOR= #007700];
                        }[/COLOR]
                        [URL="http://www.php.net/else"]else[/URL]
                        [COLOR= #007700]{[/COLOR]
                            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br />Er is een fout opgetreden in de query: <br />[/COLOR][COLOR= #007700];[/COLOR]
                            [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
                        }[/COLOR]
?>


En als je dit probeert?
0
Berichten
9.953
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Marjolein, vergeet nooit mysql_real_escape_string om je input te zetten. clown
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sevvlor schreef:
mysql_query("INSERT INTO aankondigingen (poster, titel, bericht, datum) 
                        VALUES (" . $_POST[poster] . ", " . $_POST[titel] . ", " . $_POST[bericht] . ", NOW())");
Plaats je daar eergens een 1 in

Daar zit de fout denk ik ook

toevoeging op 8 april 2012, 00:57:09:
Sebastiaanh schreef:
Marjolein, vergeet nooit mysql_real_escape_string om je input te zetten. clown
Ik dacht ook al dat daar een fout kon zitten, maar ik dacht: "Die Marjolein zal daar wel niet met haakjes gaan prutsen" yummie
0
Marjolein

Lid · Topicstarter

Berichten
15.446
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Vriendje schreef:
[COLOR= #0000BB]<?php
$toevoegquery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO aankondigingen (poster, titel, bericht, datum)
                        VALUES ("[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]poster[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]", "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]titel[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]", "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]", NOW())"[/COLOR][COLOR= #007700]);[/COLOR]

                        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$toevoegquery[/COLOR][COLOR= #007700]))
                            {[/COLOR]  
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]tot nu toe gaat het goed :D[/COLOR][COLOR= #007700];
                        }[/COLOR]
                        [URL="http://www.php.net/else"]else[/URL]
                        [COLOR= #007700]{[/COLOR]
                            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br />Er is een fout opgetreden in de query: <br />[/COLOR][COLOR= #007700];[/COLOR]
                            [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
                        }[/COLOR]
?>
En als je dit probeert?

echo wordt niet weergegeven.
Sebastiaanh schreef:
Marjolein, vergeet nooit mysql_real_escape_string om je input te zetten. clown
I know...

@sevvlor: helpt ook niks
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
GEVONDEN pompom
$toevoegquery = mysql_query("INSERT INTO aankondigingen (poster, titel, bericht, datum)
VALUES (" . $_POST[poster] . ", " . $_POST[titel] . ", " . $_POST[bericht] . ", NOW())");

if(mysql_query($toevoegquery))

1 keer lijkt me genoeg biggrin
0
Marjolein

Lid · Topicstarter

Berichten
15.446
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
oke, nu ben ik een stapje verder. Ik krijg geen error meer maar de mail wordt niet verstuurd...
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
$mailadres = $ufetch[email];
$subject  = "Nieuwe aankondiging ".$sitenaam;

$mail = mail($mailadres, $subject, $bericht, $headers, From: .$sitenaam. <.$sitemail.>);


Probeer dit alvast eens om te beginnen.
En als het nog steeds niet werkt (Waarschijnblijk) dan probeer je dit eens en kijk je of dat werkt. Dan weten we waar de fout zit.

$mailadres = $ufetch[email];
$subject  = "Nieuwe aankondiging ".$sitenaam;

$mail = mail($mailadres, $subject, $bericht, $headers);


Als dit het niet doet ligt het wss aan de headers.
0
Marjolein

Lid · Topicstarter

Berichten
15.446
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik ga het morgen uittesten, maar weet je wat ik zo raar vind...ik heb dit script op 2 verschillende hosts staan, op de 1 werkt het prima en op de andere niet confused
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Marjolein schreef:
Ik ga het morgen uittesten, maar weet je wat ik zo raar vind...ik heb dit script op 2 verschillende hosts staan, op de 1 werkt het prima en op de andere niet confused
Op welke host staat dit dan? Want sommige hosts hebben de mail functie uit staan.
0
Berichten
5.897
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
redface geen mysql_real_escape_string redface
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Marjolein schreef:
Eerdere citaten tonen
Sebastiaanh schreef:
Marjolein, vergeet nooit mysql_real_escape_string om je input te zetten. clown
I know...

@sevvlor: helpt ook niks
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren