【发布时间】:2013-11-28 15:09:16
【问题描述】:
我正在尝试关注这个先前回答的问题How to check if value already exists in MySQL database
这是我的代码
<?php
$con=mysql_connect(Localhost,"mwtwoone_xbl","password","mwtwoone_xbl");
mysql_select_db( 'mwtwoone_xbl' );
$txn_id = $_GET['txn'];
echo $txn_id;
$checktxnID = mysql_query("SELECT txn_id from codes WHERE txn_id = '$txn_id'");
if (!$checktxnID) {
die('Query failed to execute for some reason');
}
if (mysql_num_rows($checktxnId) > 0) {
echo "User id exists already.";
$user = mysql_fetch_array($checktxnId);
print_r($user); // the data returned from the query
}
echo "User id doesnt exist";
mysql_close($con);
?>
$txn_id 将被定义,我只需要检查它的值是否已经在列 txn_id 的表代码中。感谢大家的帮助,非常感谢。
现在当我访问 URL .php?txn=123 我得到 123 用户 ID 不存在。 问题是,表代码columb txn_id 上的多行包含值123!
【问题讨论】:
-
哦哦。我想首先说 mysql_* 函数已被弃用。 :)
-
然后呢?有什么错误吗?有什么问题?
-
啊,很抱歉,更新了原帖。
-
将
LIMIT 1添加到您的查询中。 -
请仔细阅读此内容,您很容易接受注射 => stackoverflow.com/q/60174/1415724
标签: php mysql duplicates