Jespar schreef:Ik weet niet of ik goed bezig ben maar ik wil een licentie systeem in, als je het wachtwoord voorbeeld intypt is ie goed en de rest niet goed. Als hij goed is moet hij een pagina showen[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$password[/COLOR][COLOR= #007700]==[/COLOR]voorbeeld[COLOR= #007700]) {[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Goedzo[/COLOR][COLOR= #007700];[/COLOR] [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]();[/COLOR] [COLOR= #FF8000]// dit is uitzondering, weet dat het afgeraden is[/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]Kijk hem nog eens na![/COLOR][COLOR= #007700]; }[/COLOR] ?> <form method="post" action="index.php"> Wachtwoord<br /> <input type="password" name="password" /><br /> <input type="submit" name="submit" value="Log in" /> </form>
Vragen topic van mij
Leer het eens. Kijk op de vorige pagina en controleer dus of er wel op het submit knopje is gedrukt.
toevoeging op 18 februari 2012, 17:03:02:
En $password bestaat niet. Het zal $_POST[password] moeten zijn.
toevoeging op 18 februari 2012, 17:03:02:
En $password bestaat niet. Het zal $_POST[password] moeten zijn.
Ja, dacht er net aan
toevoeging op 18 februari 2012, 17:04:35:
Hij werkt!
toevoeging op 18 februari 2012, 17:04:35:
Hij werkt!
[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]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"DELETE FROM moppen WHERE id = "[/COLOR][COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR]htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]])) .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][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= #DD0000]Succesvol verwijderd! <a href="index.php">Klik hier</a>[/COLOR][COLOR= #007700];
}[/COLOR]
?> Waarom laat hij succesvol verwijderd al zien, terwijl hij hem nog niet eens verzonden heeft?
toevoeging op 19 februari 2012, 19:42:01:
Laatmaar Met:
if(isset($_POST[submit]))
Werkt hij
En met:
if($_SERVER[REQUEST_METHOD]="POST")
Faalt ie!
Jespar schreef:Waarom laat hij succesvol verwijderd al zien, terwijl hij hem nog niet eens verzonden heeft?[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] [COLOR= #FF8000]// hierboven moet == ipv =[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"DELETE FROM moppen WHERE id = "[/COLOR][COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR]htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]])) .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][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= #DD0000]Succesvol verwijderd! <a href="index.php">Klik hier</a>[/COLOR][COLOR= #007700]; }[/COLOR] ?>
toevoeging op 19 februari 2012, 19:42:01:
Laatmaar Met:
if(isset($_POST[submit]))
Werkt hij
En met:
if($_SERVER[REQUEST_METHOD]="POST")
Faalt ie!
Ik heb gefixt. Gebruik deze. Andere is onveilig en slecht.
if($_SERVER[REQUEST_METHOD]="POST") is fout. Je doet een vergelijking met POST, dus gebruik dan ==.
Een enkele = staat voor een toewijzing.
En doe wat aan je foutafhandeling....
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]database.php[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<h1>Categorie veranderen</h1>[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$sqla[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM categorie ORDER BY id DESC LIMIT 10"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$resa[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sqla[/COLOR][COLOR= #007700])) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<b>"[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$resa[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]categorie[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]"</b> | <b>ID: "[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #0000BB]$resa[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]] .[/COLOR][COLOR= #DD0000]"</b> <br />"[/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]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"UPDATE categorie SET categorie="[/COLOR][COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR]htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]categorie[/COLOR][COLOR= #007700]])) .[/COLOR] [COLOR= #DD0000]" WHERE id="[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]categorie[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][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= #DD0000]Succesvol veranderd! <a href="index.php">Klik hier</a>[/COLOR][COLOR= #007700];
}[/COLOR]
?>
<form method="post" action="cveranderen.php">
ID: <input type="text" name="id" /><br />
Naam: <input type="text" name="categorie" /><br />
<input type="submit" name="submit" value="Verwijder" />
</form> Waarom past hij niks aan, alles doet hij hij zeg succesvol veranderd maar hij past niks aan?!?!
Wordt het niet eerst even tijd voor fatsoenlijke foutafhandeling om je querys heen?
Nee
Jespar schreef:In dat geval: Kap met PHP en ga lekker punnikken. Als je toch zo laf bent om niks met andermands adviezen te doen, dan is PHP echt niet voor je weggelegd.Nee
je maakt je eigen trouwens wel een beetje belachelijk met die signature zo...
Bedankt, iemand anders een oplossing
Jespar schreef:Waarom past hij niks aan, alles doet hij hij zeg succesvol veranderd maar hij past niks aan?!?![COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]database.php[/COLOR][COLOR= #007700]);[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<h1>Categorie veranderen</h1>[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #0000BB]$sqla[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM categorie ORDER BY id DESC LIMIT 10"[/COLOR][COLOR= #007700]);[/COLOR] [URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$resa[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sqla[/COLOR][COLOR= #007700])) {[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<b>"[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$resa[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]categorie[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]"</b> | <b>ID: "[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #0000BB]$resa[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]] .[/COLOR][COLOR= #DD0000]"</b> <br />"[/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] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"UPDATE categorie SET categorie="[/COLOR][COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR]htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]categorie[/COLOR][COLOR= #007700]])) .[/COLOR] [COLOR= #DD0000]" WHERE id="[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]categorie[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][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= #DD0000]Succesvol veranderd! <a href="index.php">Klik hier</a>[/COLOR][COLOR= #007700]; }[/COLOR] ?> <form method="post" action="cveranderen.php"> ID: <input type="text" name="id" /><br /> Naam: <input type="text" name="categorie" /><br /> <input type="submit" name="submit" value="Verwijder" /> </form>
Zie mijn advies, en steek niet je kop in het zand.
En je bent ook behoorlijk vatbaar voor hackers. (sql injection enzo)
En je bent ook behoorlijk vatbaar voor hackers. (sql injection enzo)
Je escaped het de eerste keer wel, en de andere keer niet? Ja, lekker veilig, zoals Aarclay al zegt.
