Kleine Vragen Topic #2

Gestart doorKingunit3.067 reacties11.764 weergaven

3.068 berichten · pagina 27 van 205

Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Sanderc schreef:
Eerdere citaten tonen
Rik schreef:
$verzetrang = mysql_query("
UPDATE
leden
SET
rang = 1
WHERE
voornaam = ".$_POST[verzet_naam]."");

if(!$res = mysql_query($verzetrang))

Je probeert het resultaat van een query nogmaals in een mysql_query te gooien. Dat werkt natuurlijk niet.

Bovendien moet je input van gebruikers ALTIJD escapen!!!

Hoe bedoel je?
SQL-injection tegen gaan.... mysql_real_escape_string()

Persoonlijk verwijder ik nooit gebruikers. Mocht je e.v.t. koppelingen hebben voor forumposts, nieuwsreacties, dan zijn deze reacties ook weg, wat niet altijd gewenst is. Ik raad aan om die users dan te markeren als verwijderd. thumbsup
0
Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ja, maar het is om mysql te leren. Dus dat probeer ik ook even.

Oke, maar ik bedoelde met dat escapen, wat je daarmee beeoeld
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Sanderc schreef:
Ja, maar het is om mysql te leren. Dus dat probeer ik ook even.
Oke, maar ik bedoelde met dat escapen, wat je daarmee beeoeld

http://php.net/mysql_real_escape_string

toevoeging op 7 mei 2013, 19:56:29:
Raaoul schreef:
klopt niet dylan...

"DELETE FROM users WHERE username = Sander"
Oh naja was op telefoon en vroeg in de ochtend.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
En die functie moet je over ALLE POST/GET/COOKIE/SERVER variabelen halen in je queries...
0
Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Oke, en zo dan? Zo werkt het niet, nu zegt hij altijd dat er niks verwijderd is of geaanpast...

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]"config.php"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]"functions.php"[/COLOR][COLOR= #007700];[/COLOR]


[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR]checklogin[COLOR= #007700]()) 
{[/COLOR]
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$get_userdata[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]rang[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700])
    {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000] <h1>Verwijder lid</h1>[/COLOR][COLOR= #007700];[/COLOR]
        
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verwijder_lid[/COLOR][COLOR= #007700]]))
        {[/COLOR]

            [COLOR= #0000BB]$verwijder_lid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"DELETE FROM leden WHERE naam= "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]delete_who[/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/mysql_affected_rows"]mysql_affected_rows[/URL][COLOR= #007700]() ==[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]) 
            {[/COLOR] 
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Geen records verwijderd. <br />Query: [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$verwijder_lid[/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 zijn [/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_affected_rows"]mysql_affected_rows[/URL][COLOR= #007700]().[/COLOR][COLOR= #DD0000] records verwijderd uit de database.[/COLOR][COLOR= #007700]; 
            } 
        }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
        [COLOR= #007700]{[/COLOR]
        ?>
            <form action="#" method="post">
                <input type="text" name="delete_who"><br/>
                <input type="submit" name="verwijder_lid" value="Verwijder dit lid">
            </form>
        [COLOR= #0000BB]<?php[/COLOR]
        [COLOR= #007700]}[/COLOR]
    
    
        [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000] <h1>Maak admin</h1>[/COLOR][COLOR= #007700];[/COLOR]
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verander_rang[/COLOR][COLOR= #007700]]))
        {[/COLOR]
            [COLOR= #0000BB]$verzetrang[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"
            UPDATE 
            leden
            SET 
            rang = 1 
            WHERE 
            username = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verzet_naam[/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/mysql_affected_rows"]mysql_affected_rows[/URL][COLOR= #007700]() ==[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]) 
            {[/COLOR] 
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Geen records gewijzigd. <br />Query: [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$verzetrang[/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]Update was succesvol![/COLOR][COLOR= #007700]; 
            } 
        }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
        [COLOR= #007700]{[/COLOR]
        ?>
        <form action="#" method="post">
            <input type="text" name="verzet_rang"><br/>
            <input type="submit" name="verander_rang" value="Maak hem admin">
        </form>
        [COLOR= #0000BB]<?php[/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 hebt het recht niet om deze pagina te bezoeken.[/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 hebt het recht niet om deze pagina te bekijken. [/COLOR][COLOR= #007700];
}[/COLOR]
?>
0
Leax

Lid

Berichten
347
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik weet niks van die mysql_affected_rows() functie he,
maar moet je niet mysql_affected_rows($verwijder_lid) zetten?
0
Thom

Lid

Berichten
10.654
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Leax schreef:
Ik weet niks van die mysql_affected_rows() functie he,
maar moet je niet mysql_affected_rows($verwijder_lid) zetten?
Nee.
0
Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Thommity schreef:
Eerdere citaten tonen
Leax schreef:
Ik weet niks van die mysql_affected_rows() functie he,
maar moet je niet mysql_affected_rows($verwijder_lid) zetten?

Nee.
Wat dan? cry
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Thommity schreef:
Eerdere citaten tonen
Leax schreef:
Ik weet niks van die mysql_affected_rows() functie he,
maar moet je niet mysql_affected_rows($verwijder_lid) zetten?

Nee.
Dat moet wel.
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Doe eens een goede foutafhandeling om te kijken of de query wel goed gegaan is.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Leax schreef:
Ik weet niks van die mysql_affected_rows() functie he,
maar moet je niet mysql_affected_rows($verwijder_lid) zetten?

Er is ook php.net wink
Sanderc schreef:
Oke, en zo dan? Zo werkt het niet, nu zegt hij altijd dat er niks verwijderd is of geaanpast...
[knip]


En ik zie een flinke SQL-injection. Pas dat gewoon consequent toe, en direct als je een query uitschrijft. Gewoon aanleren.
0
Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Oke ik zal dat morgen eens googlen, want op phptuts.nl kreeg ik er ene foute aangeleerd?
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Wat dan? Kan ik me niet voorstellen?
0
Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR] 
[URL="http://www.php.net/require_once"]require_once[/URL] [COLOR= #DD0000]db_config.php[/COLOR][COLOR= #007700];[/COLOR] 

[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]" 
    UPDATE 
        werknemers 
    SET 
        salaris_schaal = 12 
    WHERE 
        voornaam = Tim 
"[/COLOR][COLOR= #007700];[/COLOR] 

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][COLOR= #0000BB]$res[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700])) 
{[/COLOR] 
    [URL="http://www.php.net/trigger_error"]trigger_error[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]().[/COLOR][COLOR= #DD0000]<br />In query: [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]); 
}[/COLOR] 
[URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_affected_rows"]mysql_affected_rows[/URL][COLOR= #007700]() ==[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]) 
{[/COLOR] 
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Geen records gewijzigd. <br />Query: [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$sql[/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]Update was succesvol![/COLOR][COLOR= #007700]; 
}[/COLOR] 
?>


Of is er hier geen foutzfhandeling in?
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Dat klopt gewoon? smile
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