While

Gestart doorWouterp42 reacties105 weergaven

43 berichten · pagina 3 van 3

Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Juist maar toch werkt het script van aarclay niet.

[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/require"]require[/URL] [COLOR= #DD0000]connect.php[/COLOR][COLOR= #007700];[/COLOR] ?>
<table border="1" width=500>
<tr>
  <td><marquee direction="left"  hspace=40><b>Berichten: &nbsp;&nbsp;</b>[COLOR= #0000BB]<?php
$result_select[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM  berichtenbalk ORDER BY id DESC"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result_select[/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]$result_select[/COLOR][COLOR= #007700])>[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]){[/COLOR]
        [COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result_select[/COLOR][COLOR= #007700]);[/COLOR]
        [COLOR= #0000BB]$result_insert[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO 
                    berichtenbalk(
                        berichten, 
                        poster, 
                        ip
                    ) 
                    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]bericht[/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]naam[/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]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REMOTE_ADDR[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]"
                    );
                    "[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result_insert[/COLOR][COLOR= #007700]) {[/COLOR]
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Location: ./berichtenbalk.php[/COLOR][COLOR= #007700]);[/COLOR]
                        [URL="http://www.php.net/exit"]exit[/URL][COLOR= #007700]();
        }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Er is een fout opgeteden bij het invoegen(r.11): "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
        }    
    
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Er zijn nog geen berichten geplaatst."[/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]"Er is een fout opgeteden bij het uitlezen (r.3): "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
}[/COLOR]
?>
</marquee></td>
</tr>
</table>

<form name="input" action="">
<b>Naam</b></br>
<input type=text name="naam" autocomplete="off"/></br>
<b>Bericht(Maximaal 30 tekens)</b></br>
<input type="text" name="bericht" autocomplete="off" maxlength="30" /></br>
<input type="submit" value="Plaats een bericht" />
</form>


Hij zet niks in de database
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Vriendje schreef:
En wie klaagt er altijd dat we exit of die function gebruiken?

Ik, alleen als je hem verkeerd gebruikt. Maar hier gebruik ike hem goed.
Je weet wat die location doet?

nee, verdiep je er eens in.... smile
Goededag schreef:
Juist maar toch werkt het script van aarclay niet.
Hij zet niks in de database

Wat doet hij dan wel, wees a.u.b. een wat specifieker.
Ik zie wel dat je nergens controleert of je formulier verstuurd is.... Bouw dat eerst eens in.
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Aarclay schreef:
Eerdere citaten tonen
Vriendje schreef:
En wie klaagt er altijd dat we exit of die function gebruiken?
Ik, alleen als je hem verkeerd gebruikt. Maar hier gebruik ike hem goed.
Je weet wat die location doet?

nee, verdiep je er eens in.... smile
Jawel wink
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Dan weet je dat die exit() hier wel goed van pas komt, omdat het script toch niet meer verder zou moeten gaan na een location.
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik begrijp niet de complete delen van jouw script dus als jij het even zou kunnen doen met uitleg.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Wat snap je dan niet?

het neemt niet weg dat het nog fout is, en dat je nog een formulier-controle in moet bouwen met:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]]==[/COLOR][COLOR= #DD0000]"POST"[/COLOR][COLOR= #007700]) {[/COLOR]
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Kijk ik heb nu dit:

berichtenbalk.php

[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/require"]require[/URL] [COLOR= #DD0000]connect.php[/COLOR][COLOR= #007700];[/COLOR] ?>
<table border="1" width=500>
<tr>
  <td><marquee direction="left"  hspace=40><b>Berichten: &nbsp;&nbsp;</b>[COLOR= #0000BB]<?php
$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM  `berichtenbalk` "[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]) {[/COLOR]
  [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700])) {[/COLOR] [COLOR= #FF8000]// assoc is sneller.[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<b>"[/COLOR][COLOR= #007700].[/COLOR]htmlentities[COLOR= #007700]([/COLOR][URL="http://www.php.net/ucfirst"]ucfirst[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]poster[/COLOR][COLOR= #007700]])).[/COLOR][COLOR= #DD0000]</b>: [/COLOR][COLOR= #007700].[/COLOR]htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]berichten[/COLOR][COLOR= #007700]]).[/COLOR][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]"Er is een fout opgetreden: "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]berichten[/COLOR][COLOR= #007700]][/COLOR]
?>
</marquee></td>
</tr>
</table>

<form name="input" action="berichtenbalk_post.php">
<b>Naam</b></br>
<input type=text name="naam" autocomplete="off"/></br>
<b>Bericht(Maximaal 30 tekens)</b></br>
<input type="text" name="bericht" autocomplete="off" maxlength="30" /></br>
<input type="submit" value="Plaats een bericht" />
</form>


en berichtenbalk_post.php

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/require"]require[/URL] [COLOR= #DD0000]connect.php[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]]==[/COLOR][COLOR= #DD0000]"POST"[/COLOR][COLOR= #007700])[/COLOR]
[COLOR= #0000BB]$result_select[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM  berichtenbalk ORDER BY id DESC"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result_select[/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]$result_select[/COLOR][COLOR= #007700])>[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]){[/COLOR]
        [COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result_select[/COLOR][COLOR= #007700]);[/COLOR]
        [COLOR= #0000BB]$result_insert[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO 
                    berichtenbalk(
                        berichten, 
                        poster, 
                        ip
                    ) 
                    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]bericht[/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]naam[/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]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REMOTE_ADDR[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]"
                    );
                    "[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result_insert[/COLOR][COLOR= #007700]) {[/COLOR]
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Location: ./berichtenbalk.php[/COLOR][COLOR= #007700]);[/COLOR]
                        [URL="http://www.php.net/exit"]exit[/URL][COLOR= #007700]();
        }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Er is een fout opgeteden bij het invoegen(r.11): "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
        }    
    
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Er zijn nog geen berichten geplaatst."[/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]"Er is een fout opgeteden bij het uitlezen (r.3): "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
}[/COLOR]
?>


Het zet niks in de database en het linkt niet door naar berichtenbalk.php hoe fix ik dit.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Ik zie dat je wel je if statement op lijn 3 moet starten en beëindigen... wink
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Gelukt! Dankjewel.
0
Berichten
994
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Gebruik PHPDesigner, dan zie je gelijk waar de fout zit.
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik gebruik phpDesigner 8.0 smile
0
Berichten
3.112
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Of gebruik Notepad++. Ook zeker een aanrader wink (Voor meerdere talen)
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Of Netbeans....

Nog handiger... pompom
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