English 中文(简体)
是什么导致 PHP 函数打印出错误文字模糊, 而不是其他错误文字模糊?
原标题:What is causing one PHP function to print out error text blurb, but not another?

我正在用Netbeans在 PHP 中建立注册/登录格式。 为了执行此功能, 我在一个脚本. php 文件中拥有我的登录、 注册和数据库连接功能, 它通过包含的电话装入 。

我的登录功能用这个

$username = mysql_real_escape_string($_POST[ username ]);
$password = sha1(mysql_real_escape_string($_POST[ password ]));
$query = sprintf("SELECT * FROM users WHERE username= %s  AND password= %s ", $username, $password);

$link = connectDB();

$results = mysqli_query($link, $query);

以连接到 db 并获取结果。验证将在以后进行。

我的注册逻辑,我几乎用同样的东西:

$username = mysql_real_escape_string($_POST[ username ]);
$password = mysql_real_escape_string($_POST[ password ]);

//check if user name and password match conditions
$link = connectDB();
$query = "SELECT * FROM users WHERE username =  " . $username . " ";
$results = mysqli_query($link, $query);

注册页加载精细, 但登录页有错误的文字打印, 表示登录函数中有一个未定义的索引用户名。 这在页面加载时发生, 没有调用任何函数 。

然而,由于注册功能的布局几乎相同,我不明白错误。

为什么发生这种情况?

<强 > EDIT

我找到问题了

我当时使用 mysqli_ connect 打开数据库连接,但使用 mysql-real_escape_string 函数。 两者不兼容, 添加 > 使所有功能都不同 。

最佳回答

有几点可能与你的问题有关,也可能与你的问题无关,但我不能忽视:

  1. SQL-escaping a string is always the last thing that happens. Don t SQL-escape a string, then sha1 it. See The Great Escapism to learn what escaping is all about.
  2. When using mysql_real_escape_string, you need to connect to the database first before calling this function, since it needs to have an established database connection to do its job.
  3. You are mixing the mysql and mysqli extensions. Use one or the other, not functions of both.
  4. If you re using mysqli (and you should!), use prepared statements instead of manually SQL-escaping the string and sprintf.

换句话说,你现在做的完全错误。先解决那些事情,你的问题可能随心所欲。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签