[PHP] Probleem in mn query of niet?

Gestart doorJosnl8 reacties32 weergaven

9 berichten · pagina 1 van 1

Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo allemaal,

Omdat ik er zelf niet uitkom zal ik mijn probleem hier zo duidelijk mogelijk proberen uit te leggen:

Ik heb een script gemaakt waarmee je een bericht in de database kan zetten, echter wordt er niks in de database gezet én komen de foutmeldingen vóór het submitten van het formulier.

Dit is mijn script:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/session_start"]session_start[/URL][COLOR= #007700]();[/COLOR]
[URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"config.php"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/ob_start"]ob_start[/URL][COLOR= #007700]();[/COLOR]
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title>MijnSexyFoto</title>
    
    <link rel="stylesheet" type="text/css" href="style.css" />
    
</head>


    <body>

        <div id="header"><div id="login">
                            <form action="" method="post">                            
                               <input type="text" border="0" class="login_input" name="naam" value="Gebruikersnaam" onBlur="if(this.value == ) { this.value=Gebruikersnaam}" 
                            onfocus="if (this.value == Gebruikersnaam){this.value=}" />
                            
                            <input type="password" border="0" class="login_input2" name="pass" value="mijnwachtwoord" onBlur="if(this.value == ) { this.value=mijnwachtwoord}" 
                            onfocus="if (this.value == mijnwachtwoord){this.value=}" />
                            <input type="submit" class="login_submit" border="0" value="." />
                            </form>
                    
        </div></div>   
        
            <div id="menu">    <a href="#">Startpagina</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <a href="#">Registreren</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <a href="#">Fotos</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <a href="#">Leden</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <a href="#">Tell-a-friend</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <a href="#">Bookmark</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <a href="#">Info</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <a href="#">Contactformulier</a>
            </div>
            [COLOR= #0000BB]<?php 
            
            $bQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT aan FROM berichten WHERE aan="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
            [COLOR= #0000BB]$bAantal[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$bQuery[/COLOR][COLOR= #007700]);[/COLOR]
            [COLOR= #0000BB]$bTotaal[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$bAantal[/COLOR][COLOR= #007700];[/COLOR]
            
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]])){[/COLOR]
                    
                        [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000][/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]<div id="leden_menu">
                                            <div class="bericht"></div>&nbsp;&nbsp;Berichten <strong>([/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$bAantal[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000])</strong>
                        </div>[/COLOR][COLOR= #007700];
                    
            }[/COLOR]
            
            ?>
            
                <div class="container">
            
                        <div class="content-top">Controlepaneel</div>
                        <div class="content-mid">
                        
                         [COLOR= #0000BB]<?php[/COLOR] 
 
                            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]])) {[/COLOR]  
                            
                         [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<div class="fout">Je bent niet ingelogged.<br /></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]"
                            <form action="" method="post">                            
                               <input type="text" border="0" class="login_input" name="aan" value="Aan" onBlur="if(this.value == ) { this.value=Aan}" 
                            onfocus="if (this.value == Aan){this.value=}" />
                            
                            <input type="text" border="0" class="login_input" name="bericht" value="Bericht" onBlur="if(this.value == ) { this.value=Bericht}" 
                            onfocus="if (this.value == Bericht){this.value=}" />
                            <input type="submit" border="0" value="Verstuur bericht" />
                            </form>"[/COLOR][COLOR= #007700];
                                
                            }[/COLOR]
                            
                            ?>
                            
                            <div class="fout">
                            
                            [COLOR= #0000BB]<?php[/COLOR]
                            
                            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aan[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]"Aan"[/COLOR][COLOR= #007700]){[/COLOR]
                                
                                [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]Je hebt geen ontvanger ingevuld.<br />[/COLOR][COLOR= #007700];
                                
                            }[/COLOR]
                            
                            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]"Bericht"[/COLOR][COLOR= #007700]){[/COLOR]
                                
                                [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]Je hebt geen bericht ingevuld.[/COLOR][COLOR= #007700];
                                
                            }[/COLOR][URL="http://www.php.net/else"]else[/URL][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= #DD0000]"INSERT INTO `berichten` (aan,inhoud,datum) VALUES (
                                                                                "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aan[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]",
                                                                                "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][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/echo"]echo[/URL][COLOR= #DD0000]Je bericht is succesvol verstuurd![/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]Je bericht is niet verzonden, probeer het later nog eens.[/COLOR][COLOR= #007700];
                                    
                                }
                                
                            }[/COLOR]
                            
                            ?>
                            
                            </div>
                        
  
                                                   
                          </div>
                        
                        <div class="content-bottom"></div>

                        <div id="copyright">&copy; Copyright MijnSexyFoto 2010-2011  |  Alle rechten voorbehouden</div>
            
                </div>  
            
    </body>
    

</html>


Degene die mij de juiste oplossing weet te vertellen krijgt van mij 0.1pt! biggrin
Alvast bedankt allemaal,

Gr. Josbiggrin
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
|| "Aan"
emo?
0
Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dat is omdat een input bij mijn form nooit leeg is, dat heb ik met javascript gedaan. Leeg is dus eigenlijk gewoon Aan, snapje?

Nu graag alleen nog reacties van mensen die er w¨¦l verstand van hebben.biggrin
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Sorry hoor maar dit kan niet:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aan[/COLOR][COLOR= #007700]] ||[/COLOR]  [COLOR= #DD0000]"Aan"[/COLOR][COLOR= #007700]){[/COLOR]
[COLOR= #FF8000]//Dit kan wel:[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aan[/COLOR][COLOR= #007700]]{[/COLOR]
?>
0
Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ehh en waarom kan dat dan niet? yummie
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
if($_POST[aan] || "Aan"){

Staat voor

Als $_POST[aan] OF "Aan"

Zou jij dan snappen wat je moet dan als jij de computer was?

Als je echt dit doet:

if(!empty($_POST[aan]) || $_POST[aan] =="Aan") { [...] }

Dan kan het wel:

Als $_POST[aan] niet leeg is OF $_POST[aan] gelijk is aan "Aan"
0
Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Oh oke, dat heb ik inmiddels veranderd. smile
Haalt helaas niks uit, nja, de gegevens worden nog niet in de database gezet. De foutmeldingen worden nu in ieder geval niet getoond voordat er op versturen gedrukt is.

Iemand die misschien een foutje ergens in de query ziet? bloos
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
mysql_query("INSERT INTO `berichten` (aan,inhoud,datum) VALUES (
                                                                                ".mysql_real_escape_string($_POST[aan]).",
                                                                                ".mysql_real_escape_string($_POST[bericht]).",
                                                                                NOW()
                                                                                                   )");
0
Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dankje Niels, hij wordt nu wel verstuurd alleen moest ik die laatste else verwijderen om hem met jou query werkend te maken. Zou jij hem misschien zo in mijn script kunnen zetten dat hij het bericht in de database zet ¨¦n een bericht geeft dat het is gelukt?

Alvast heel erg bedankt!biggrin
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