mysql - PHP: if condition then redirect1 else redirect2 -
i'm trying make simple check here. want select db record represents username , password. problem if
starts. whether i'm putting in form credentials exist in database or not still don't redirected. besides using mysqli_num_fields($result)
, tried using mysqli_num_rows($result)
, still doesn't work. starting drive me nuts.
also tried var_dump of $result , got this:
object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(1) ["lengths"]=> null ["num_rows"]=> int(0) ["type"]=> int(0) }
which i'm not sure how interpret.
<?php $con=mysqli_connect("localhost","root","xxxxx","test"); $pass = $_post['pass']; $uid = $_post['uid']; $result = mysqli_query($con, "select uid test.login uid = '$uid' , pass = '$pass'"); if(mysqli_num_fields($result) == 0) { header('location: index.html')} else { header('form.html')} mysqli_close($con); ?>
thanks in advance. rather stupid question , apologize that, understand i'm rather new in lamp.
you should send right header. bit of formatting reveals difference between if- , else-branch:
if(mysqli_num_fields($result) == 0) { header('location: index.html') } else { header('form.html') }
you should use
if(mysqli_num_fields($result) == 0) { header('location: index.html'); } else { header('location: form.html'); }
instead.
as @u_mulder remarked, php-docu mentions no such function/method mysqli_num_fields(). code prone sql-injection, should escape user input mysqli_real_escape_string(). better: use prepared statements. successful login should depend of 1 matching row in result.
a sidenote: it's bad idea store cleartext passwords.
Comments
Post a Comment