dongwen1935 2015-12-31 08:32
浏览 59
已采纳

比较两个值的比较失败

I am trying to compare two variables one is getting fetched from database and other is a textbox value.

If comparison is successful then the if statement block will return the value as matched and if they don't else statement block will return not matched.

But it is always returning not matched even if I enter same value that is in the database.

My code is this:

<?php
   error_reporting(0);
   $user_id = 5;

   $dbhost = 'localhost';
   $dbuser = 'root';
   $dbpass = '';
   $conn = mysql_connect($dbhost, $dbuser, $dbpass);
   mysql_select_db('qurefle');
   if(! $conn )
   {
      die('Could not connect: ' . mysql_error());
   }
   if(isset($_POST["blccrcc"])){
     $sql = 'SELECT l_coupon_c FROM cc_generator WHERE unique_id = "'.$user_id.'"';

     $retval = mysql_query( $sql, $conn );

   if(! $retval )
   {
      die('Could not get data: ' . mysql_error());
   }

   while($row = mysql_fetch_assoc($retval))
   {
      //fetching data
      $l_coupon_c = $row['l_coupon_c'];
      //Data Comparison
      $friend_cc = $_POST["lccrcc"];

      if ($l_coupon_c == $friend_cc) {
        echo"it is matched";
      }
      else{
    echo"Not Matched";
      }
  }//while bracket
}//if isset bracket  
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>LCC AND RCC Coupon Code Chain Extender</title>
</head>

<body>
<center>
<form method="POST" action="">
Friend cc: <input type="text" name="lccrcc"><br><br>
<input type="submit" value="Use Coupon Code" name="blccrcc">

</form>
</center>

</body>
</html>

My Database snapshot is this

  • 写回答

2条回答 默认 最新

  • dongwen9975 2015-12-31 08:38
    关注

    Use trim as well, sometimes there are some additional space issues too.

    if(trim($l_coupon_c) == trim($friend_cc)) 
    

    and print_r($_POST); to see the values of POST

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装