[PHP] Input blijft onjuist

Gestart doorDesire15 reacties77 weergaven

16 berichten · pagina 1 van 2

Desire

Lid · Topicstarter

Berichten
4.367
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo,

Ik ben bezig met een script alleen nu kom ik een foutje tegen.

[COLOR= #0000BB]<?php[/COLOR]
    
    [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"config.php"[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$id[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
    [COLOR= #0000BB]$code[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"SELECT code FROM codes WHERE id = "[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$id[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR] 
    [COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$code[/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/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je hebt geen code ingevoerd, je mag alleen code`s invoeren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/exit"]exit[/URL][COLOR= #007700]();
            }[/COLOR]
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]code is juist[/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]code is onjuist[/COLOR][COLOR= #007700];
            }
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
    }[/COLOR]
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]
        <form method="post">
            <input type="tekst" name="code" />
            <input type="submit" name="Submit" value="submit!" />
        </form>
    [/COLOR][COLOR= #007700];[/COLOR]
?>


Zodra ik een code invul dan blijft hij onjuist zeggen terwijl ik wel de goede code invul.

Wie kan me helpen.

Mvg,
Desire
0
Berichten
1.871
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik neem aan dat de code 1 is?

toevoeging op 24 mei 2013, 19:33:52:
if($_POST[code] == ) {

kun je beter vervangen door:

if(empty($_POST[code])) {
0
Desire

Lid · Topicstarter

Berichten
4.367
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sorry! haha ik wil graag dat de code uit de database werkt aar hoe doe ik dat dan..
0
Berichten
1.871
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik maak het wel voor je wink
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Nielsjojo schreef:
Ik neem aan dat de code 1 is?
toevoeging op 24 mei 2013, 19:33:52:
if($_POST[code] == ) {

kun je beter vervangen door:

if(empty($_POST[code])) {

Je kan beter gewoon trim() doen. Dus if(trim($_POST[code]) == )
0
Berichten
1.871
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/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/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]$id[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]];[/COLOR]
            [COLOR= #0000BB]$code[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"SELECT code FROM codes WHERE id = "[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$id[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR] 
            [COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$code[/COLOR][COLOR= #007700]);[/COLOR] 
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/trim"]trim[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]]) ==[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je hebt geen code ingevoerd, je mag alleen code`s invoeren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/exit"]exit[/URL][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[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]code is juist[/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]code is onjuist[/COLOR][COLOR= #007700];
            }
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
    }[/COLOR]
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]
        <form method="post">
            <input type="tekst" name="code" />
            <input type="submit" name="Submit" value="submit!" />
        </form>
    [/COLOR][COLOR= #007700];[/COLOR]
?>


Edit: Dylancoools tip voor [func]trim[/func] toegevoegd!
0
Berichten
1.871
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Probeer dit eens:

[COLOR= #0000BB]<?php[/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/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]$id[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]];[/COLOR]
            [COLOR= #0000BB]$code[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"SELECT * FROM codes WHERE code = "[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$id[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR] 
            [COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$code[/COLOR][COLOR= #007700]);[/COLOR] 
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/trim"]trim[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]]) ==[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je hebt geen code ingevoerd, je mag alleen code`s invoeren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/exit"]exit[/URL][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[/COLOR][COLOR= #007700]) !==[/COLOR] [COLOR= #DD0000]0[/COLOR][COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]code is juist[/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]code is onjuist[/COLOR][COLOR= #007700];
            }
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
    }[/COLOR]
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]
        <form method="post">
            <input type="tekst" name="code" />
            <input type="submit" name="Submit" value="submit!" />
        </form>
    [/COLOR][COLOR= #007700];[/COLOR]
?>
0
Desire

Lid · Topicstarter

Berichten
4.367
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zelfde probleem op juist xD

toevoeging op 24 mei 2013, 201821:
Nielsjojo heeft het via teamviewer opgelost.
0
Berichten
1.871
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Graag gedaan wink
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Misschien de oplossing even in het topic posten.
0
Desire

Lid · Topicstarter

Berichten
4.367
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/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/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]$id[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]];[/COLOR]
            [COLOR= #FF8000]//$code = "SELECT * FROM codes WHERE code = " . mysql_real_escape_string($id) . ""; 
           // $result = mysql_query($code); [/COLOR]
           [COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM codes WHERE code = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$id[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/trim"]trim[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]]) ==[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je hebt geen code ingevoerd, je mag alleen code`s invoeren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/exit"]exit[/URL][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[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]code is juist[/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]code is onjuist[/COLOR][COLOR= #007700];
            }
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
    }[/COLOR]
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]
        <form method="post">
            <input type="tekst" name="code" />
            <input type="submit" name="Submit" value="submit!" />
        </form>
    [/COLOR][COLOR= #007700];[/COLOR]
?>
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Vanwaar die exit() nergens voor nodig. je script moet niet stoppen, hij moet gewoon een deel code overslaan.
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Je vergeet mysql_real_escape_string
0
Desire

Lid · Topicstarter

Berichten
4.367
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zal het aanpassen.

toevoeging op 25 mei 2013, 14:43:07:
Dit is mijn code nu:

[COLOR= #0000BB]<?php[/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/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]$id[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]];[/COLOR]
           [COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM codes WHERE code = "[/COLOR][COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$id[/COLOR][COLOR= #007700]) .[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/trim"]trim[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]]) ==[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je hebt geen code ingevoerd, je mag alleen code`s invoeren![/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[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]code is juist[/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]code is onjuist[/COLOR][COLOR= #007700];
            }
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
    }[/COLOR]
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]
        <form method="post">
            <input type="tekst" name="code" />
            <input type="submit" name="Submit" value="submit!" />
        </form>
    [/COLOR][COLOR= #007700];[/COLOR]
?>


En hij werkt nog prima yummie
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