php - People can edit my form and send a string that is different from an email that mess up my databases -
my form requires email(set via input type) people use inspect element , submit other values not email. 1 of them percent sign , messes databases badly. tried checking percent sign didnt help. here's code, please give me lead or tell me what's wrong?
thanks
if(strpos($_post['email'], '%') == false) { $curpass = strtoupper(hash("whirlpool", $_post['curpass'])); $passii = $con->prepare("select `password` `playerinfo` `playername` = ?;"); $passii->execute(array($_session["playername"])); while($row = $passii->fetch()) { $curpass1 = $row['password']; } if($curpass == $curpass1) { $email = mysql_escape_string($pemail); echo "<div class='flash_success'>your email has been changed.</div>"; $p_name_settings = $_session['playername']; $updatemail = $con->prepare("update `playerinfo` set `email` = ? `playername` = ?"); $updatemail->execute(array($pemail, $_session["playername"])); } else { echo "<div class='flash_error'>you did not enter current password correctly. settings not saved.</div>"; } }
you use filter_validate_email
, filter_sanitize_email
prevent insertion. like:
$email = $_post['email']; // remove illegal characters email $email = filter_var($email, filter_sanitize_email); // validate e-mail if (filter_var($email, filter_validate_email)) { // email valid email address $curpass = strtoupper(hash("whirlpool", $_post['curpass'])); $passii = $con->prepare("select `password` `playerinfo` `playername` = ?;"); $passii->execute(array($_session["playername"])); while($row = $passii->fetch()) { $curpass1 = $row['password']; } if($curpass == $curpass1) { $email = mysqli_real_escape_string($con, $email); echo "<div class='flash_success'>your email has been changed.</div>"; $p_name_settings = $_session['playername']; $updatemail = $con->prepare("update `playerinfo` set `email` = ? `playername` = ?"); $updatemail->execute(array($pemail, $_session["playername"])); } else { echo "<div class='flash_error'>you did not enter current password correctly. settings not saved.</div>"; } }
Comments
Post a Comment