简体   繁体   English

将值从PHP传递到MySQL失败,但可以在PHPMyAdmin中使用

[英]Passing a value from PHP to MySQL fails but works in PHPMyAdmin

In my web service, when a user signs up they are given a token (in this case, it's a GUID without any separators) which is stored in a table. 在我的Web服务中,当用户注册时,会为他们提供一个令牌(在本例中是没有任何分隔符的GUID),该令牌存储在表中。

To test it's working, I go to PHPMyAdmin and in the SQL query tab enter 为了测试它是否正常工作,我转到PHPMyAdmin,然后在“ SQL查询”选项卡中输入

SELECT * FROM MyTable WHERE Token=my_guid AND Username=user AND Password=pass

this returns the row correctly 这将正确返回行

I have a web service that takes 3 parameters and performs the same SQL query, however, no rows are returned. 我有一个采用3个参数并执行相同SQL查询的Web服务,但是,没有返回任何行。 If I remove the token parameter, the row returns fine. 如果删除令牌参数,则该行返回正常值。 The table has it that the Token field is set to 42 characters. 该表将“令牌”字段设置为42个字符。

In my PHP file, the failing query looks like this 在我的PHP文件中,失败的查询如下所示

$query = "SELECT * from Login WHERE Username = '$username' AND Password = '$password' AND Token = '$token';";
$result = mysql_query($query,$link) or die('Errant query:  '.$query);

Is there some sort of terminal character stripping going on as I can't see why the query should work with the token removed but not work when it's there and in the database. 是否正在进行某种形式的终端字符剥离,因为我看不到为什么查询应该在删除令牌的情况下工作,但在令牌存在于数据库中时却无法工作。

The server is using PHP 5.6.35 服务器正在使用PHP 5.6.35

它应该是

$query = "SELECT * from Login WHERE Username = '{$username}' AND Password = '{$password}' AND Token = '{$token}';";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM