No database selected: login php code -
<?php session_start(); $con=mysqli_connect("localhost","xxx","xxxxxx","xxx"); if (mysqli_connect_errno($con)) { echo "failed connect mysql: " . mysqli_connect_error(); } $eadd = $_post['eadd']; $pass = $_post['pass']; $eadd = htmlspecialchars(stripslashes(strip_tags($eadd))); $pass = htmlspecialchars(stripslashes(strip_tags($pass))); if (filter_var($eadd, filter_validate_email)) { $sql = mysql_query("select * accounts emailadd = '$eadd' , password = '$pass'"); if(!$sql){ die('there error in query '. mysql_error()); } $count = mysql_numrows($sql) or die(mysql_error()); if ($count<=0) { echo " <html> <style> body{ background-color:#cccccc; } #error{ position:relative; margin:auto; top:20px; width:320px; height:55px; background-color:#63a8d7; border:1px solid #2a262a; } #errorc{ position:absolute; top:20px; left:20px; font: 14px arial, tahoma; } </style> <body> <div id=error> <div id=errorc> incorrect email address , password! <a href=index.php>go back</a> </div> </div> </body> </html> "; } else { //have them logged in $_session['account'] = $eadd; header('location:home.php'); } mysqli_close($con); } else { echo " <html> <style> body{ background-color:#cccccc; } #error{ position:relative; margin:auto; top:20px; width:320px; height:55px; background-color:#63a8d7; border:1px solid #2a262a; } #errorc{ position:absolute; top:20px; left:20px; font: 14px arial, tahoma; } </style> <body> <div id=error> <div id=errorc> invalid email address! <a href=index.php>go back</a> </div> </div> </body> </html> "; } ?>
why there error "no database selected"? mysqli_connect correct. have register php code, using can register email address using connection.but here in login php code, can't login user email address.
from above code using mysqli_connect
database connection , mysql_query
query execution. use mysqli_query
instead of mysql_query
. this
mysqli_query("select * accounts emailadd = '$eadd' , password = '$pass'");
Comments
Post a Comment