- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经检查了所有变量。它们都包含正确的数据。但是,当我调用 mysql_num_rows() 时,它返回 NULL,而不是 1。因此,我的登录脚本显示错误的用户名和密码,而实际上它们是正确的。
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
ob_start();
$host="mywebsite.it"; // Host name
$username="whateveruser"; // Mysql username
$password="whateverpassword"; // Mysql password
$db_name="whateverdb"; // Database name
$tbl_name="whatevertable"; // 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");
print "$db_name\n";/*These is correct*/
print "$tbl_name\n";/*These is correct*/
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
/*To protect MySQL injection*/
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
print "\n$result"; /*These is correct*/
// Mysql_num_row is counting table row
$count = mysql_num_rows($result); /*This isn't actually returning 1*/
echo '<pre>'; var_dump($count); echo '</pre>';
// 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:Target.php");
}
else {
echo "Wrong Username or Password"; /*my script always goes here*/
}
ob_end_flush();
?>
最佳答案
这看起来应该可行。但是,请停止使用 mysql_* 函数。它们已被弃用,并且存在许多安全问题。
相反,我强烈建议您使用支持 native 编码的库,例如 PDO。 ( http://www.php.net/manual/en/class.pdo.php ) 具体来说,我建议您使用准备好的语句。 (http://www.php.net/manual/en/pdo.prepare.php)
我在下面提供了一个简单的示例。
这里有一个快速连接功能:
<?php
function connectToDb($dbms, $host, $port, $username, $password) {
$dsn = sprintf('%s:host=%s;port=%d', $dbms, $host, $port);
$attributes = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
// Wrap PDO instantiation in a try->catch so credentials don't end up in
// stack traces
try {
$connection = new PDO(
$dsn, $username, $password, $attributes
);
} catch (Exception $exception) {
throw new Exception($exception->getMessage());
}
return $connection;
}
以下是如何使用它的快速示例:
// Connect to the database
$connection = connectToDb(
'mysql', 'localhost', '3306', 'bryan', ''
);
// Prepare the statement with parameters we can bind user input to
// These parameters will be properyly encoded to prevent SQL injection
$statement = $connection->prepare(
'SELECT user,password FROM mysql.user WHERE user = :username'
);
// Perform the search with the user-supplied data
// We'll pretend here with $usernameSearch
$usernameSearch = 'bryan';
$statement->execute(
array(':username' => $usernameSearch)
);
// Get the result set row count
$rowCount = $statement->rowCount();
// Do What you need to do
if ($rowCount > 0) {
// Fetch a row
$result = $statement->fetch(PDO::FETCH_ASSOC);
printf("Found a record for %s!\n", $result['user']);
} else {
echo "No record found!\n";
}
关于php - mysql num rows 返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20472933/
我知道这是基本的,但我不确定,我哪里出错了,之前从未写过正则表达式.. 我需要从命令中获取一些输出 cmd | grep '[0-9]+:[0-9]+:[0-9]+:[0-9]+' 我需要grep一些
这个问题在这里已经有了答案: How does assignment work with list slices? [duplicate] (5 个答案) What does colon at as
我在一本 C 书中读到,对于数组 num[7],术语 num 等同于 &num[0]。这个概念对我来说很好,但是当我编写如下所示的程序时,我再次感到困惑。 #include #include int
例如,一种不好的方法是通过字符串分解: toReadableNum :: (Num a, Num b, Read b) => a -> b toReadableNum = read . show 如果
在输入文本字段中,我必须获取该值并在我的 .ts 文件中使用它。你能建议我应该使用以下哪种语法吗? 最佳答案 如果您希望在文本字段中看到的内容与变量中看到的内容之间进行同步对齐,请使用 如果您想在文
我正在研究 while 循环。我目前正在研究一个问题,要求从名为 a、b 和 c 的用户那里获取三个数字。我尝试显示 a 和 b 之间的所有数字,它们除以 c。我尝试使用“if”的想法,但没有成功。
因为这些符号,我很难用谷歌搜索。 num & 8, num >> 8 和 num >> 8 & 64 在 javascript 中是什么意思? 最佳答案 它们是 bitwise operators 关
显然,我的类型签名已关闭。从那以后我发现了原因。现在,我有兴趣了解更多关于我的错字上的 GHCI 推断签名。我试图让这段代码工作: elemNum :: (Eq a, Num b) => a -> [
我有一个程序根据定义的规则接受特定的字符串,即数字运算符编号。例如:2+4-5*9/8 上面的字符串是可以接受的。现在,当我输入类似 2+4-a 的内容时,它再次显示可接受,这是完全 Not Acce
我读到了这样一个旋转数组的解决方案 问题: public class Solution { public void rotate(int[] nums, int k) { in
一般来说,对于 int num , num++ (或 ++num ),作为读-修改-写操作,是 不是原子的 .但是我经常看到编译器,比如GCC ,为其生成以下代码( try here ): void
这个问题在这里已经有了答案: What's the difference between my ($variableName) and my $variableName in Perl? (4 个回答
如果列表中的 num 大于 0.5,我想得到 1,否则得到 0。 例如,a是一个列表 Matlab: b = (a > 0.5) Python: b = [1 if x > 0.5 else 0 fo
第4行为什么要在“-”后面加上“=”? num = 5 if num > 2: print(num) num -= 1 print(num) 最佳答案 num - 1:产生num减一的
iex> num = [9] '\t' 分配单个 [9] 列表返回 '\t'。这是什么原因? 最佳答案 您可以使用 i helper in IEx有关数据类型的更多信息: iex> i [9] Te
好吧,我做错了什么 - Moose 忽略了我的强制: package moo; use Moose; use Moose::Util::TypeConstraints; subtype Bar =>
这个问题已经有答案了: JavaScript property access: dot notation vs. brackets? (17 个回答) 已关闭 4 年前。 我正在练习编写一些代码。在练
我有声明 SELECT COUNT(*) as num_requests, ip_address FROM requests GROUP BY ip_address ORDER BY num_requ
有什么方法可以在 javascript 中编写更短的 (num>0)?num:0 吗? 原因是 num 变量还没有定义,在上面的例子中需要计算两次。 换句话说,a和b是已知的。我想写 (a>b)?(a
这个问题在这里已经有了答案: Why does 2 == [2] in JavaScript? (9 个回答) 关闭 9 年前。 这些陈述的计算结果为真是否有原因? 0 == [0]; 1 == [
我是一名优秀的程序员,十分优秀!