php - Using isset with mysql_real_escape_string -
i'm new php , trying build log in system. aware it's insecure, college project in understanding basics of php, that's not problem.
i have usernames , passwords in table , trying store cookie if user types in correct username , password combination. want have pages can accessed if user logged in.
i keep getting undefined index notice. aware article http://notesofgenius.com/how-fix-php-notice-undefined-index/ need add isset somewhere, can't work out put in code. using isset mysql_real_escape_string confusing me.
i've connected database , started session in config.php. here code:
<?php require("config.php"); $username = mysql_real_escape_string($_post['username']); $password = mysql_real_escape_string($_post['password']); $result = mysqli_query($con,"select * users username='$username' , password='$password' " ); if($row = mysqli_fetch_array($result)) { $_session['user'] = 'person'; header('location: postarticle.php'); } else{ echo "<p>incorrect password</p>"; } ?>
thanks. apologies if has been asked before, did check couldn't find anything.
actually isset()
has nothing escaping. there no connection between these 2 facilities.
also, isset() won't make code working if doesn't. can save error message in case calling page regular way, without sending form it. if keep getting message form sent - check form method
, input name
attributes.
anyway, don't need isset()
here
<?php if ($_server['request_method'] == 'post') { require("config.php"); $username = mysqli_real_escape_string($con, $_post['username']); $password = mysqli_real_escape_string($con, $_post['password']); $sql = "select * users username='$username' , password='$password'"; $result = mysqli_query($con,$sql); if($row = mysqli_fetch_array($result)) { $_session['user'] = 'person'; header('location: postarticle.php'); exit; } else { echo "<p>incorrect password</p>"; exit; } }
Comments
Post a Comment