MYSQL QUERY
<?php
$host="******** "; // Host name
$username="lurnn"; // Mysql username
$password="Bondurant14!"; // Mysql password
$db_name="lurnn"; // Database name
$tbl_name="teachers"; // Table name
/ / Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql = "SELECT * FROM $teachers WHERE username='myusername' and password='mypassword';";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
我收到的错误消息:
警告:mysql_num_rows()要求参数1为资源,第27行/home/content/88/10880688/html/checklogin.php中给出布尔值 用户名或密码错误您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在第1行的“WHERE username ='mattmclaren@gmail.com”和密码=“bondurant14”附近使用正确的语法
答案 0 :(得分:1)
您必须提交表单,您正在使用的是锚标记。单击锚标记时,表单不提交值,而是告诉浏览器按照该位置。在您的情况下,checklogin.php
。
使用
<input type="submit" name="submit">
而不是
<a class="btn-glow primary signup" input type="submit" name="submit" value="login" href="checklogin.php">Sign up</a>
此外,如果您想在点击锚标记时提交表单,可以使用javascript。
答案 1 :(得分:0)
在PHP代码中尝试:
$sql = "SELECT * FROM $tbl_name WHERE username='" . $myusername . "' and password='" . $mypassword . "';";
这可能会解决问题。