hi every one...
i have a problem with mysql.
i try to create a login page.
and i wrote code below.
but this code has 2 errors:
<!doctype html><html><head><meta charset="utf-8"><title>Login page!</title> </head><body> <form action="login.php" method="post" >Username:<input name="user" type="text" >Password:<input type="text" name="password"><input type="submit" name="login_btn" value="Login!"></form> <?phpif(isset($_POST['login_btn'])){ $user_name=$_POST["user"]; $password=$_POST['password']; $conn=mysqli_connect("localhost","mojtaba", "9addsfsf93gfh6","mojidb"); $query="SELECT password FROM users WHERE username=$user_name"; $result=mysqli_query($conn,$query); $result2=mysqli_fetch_assoc($result); if(mysqli_num_rows($result)==1) { //check password if(md5($password)==$result2['password']) { //logined OK! echo "logined successfully!"; exit(); } else echo "login unsuccessful!"; }}?> </body></html>
and these are errors:
1:Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:wampwwwlogin.php on line 22
2:Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:wampwwwlogin.php on line 24
i want to help me how can i solve these errors?
and another question!
i created a register page that users can become a member.
Even though i set column of ID with PRIMARY KEY but still Repetitious usernames will create and save in the database.
how can i do this problem??? that Repetitious usernames don't save...
and at last forgive me for my bad english!