-1
<?php

$db_name="evote";  
$tbl_name="voter";

$link = mysqli_connect('localhost')or die("cannot connect");

$vid = $_GET["voterid"];$aid = $_GET["aadharid"]; $passwd = $_GET["passwd"]; 
//$vid = $_REQUEST["voterid"]; $aid = $_REQUEST["aadharid"]; $passwd = $_REQUEST["passwd"]; 

//setcookie('nvid',$vid);
//$new=$_COOKIE['nvid'];
//echo $new;

//$sql1="SELECT * FROM voter WHERE vid=$vid AND aid=$aid AND passwd=$passwd";

$sql1="SELECT name FROM voter WHERE vid= '$vid' AND aid= '$aid' AND passwd= '$passwd' ";

$val=mysqli_query($link,$sql1);

$count=mysqli_num_rows($val);

if('$count')
{
//setcookie('nvid',$vid);
//$new=$_COOKIE['nvid'];

echo "Login Success";
echo "1";
return 1;

}else {

//echo "\nLogin Failed";
echo "0";
return 0;
}

mysqli_close($link);

?>

I run the above code. But It gave same output for all inputs eventhough there is no values in the databse. I used WAMP server. I need to get output if there one tuple in the databse with the given values otherwise display 0.

  • if('$count') remove quotes because this is a variable – daremachine Jun 16 '17 at 10:17
  • `if('$count')` ?? this should be something like `if($count)` or even better `if($count > 0)` – Raymond Nijland Jun 16 '17 at 10:17
  • I made changes but now it is giving reverse case. Gives false to all inputs. That is it returns 0 to all. Is there any problem with sql statement. I think sql statement is not executing. What may be the problem? – Ganaraj Jun 19 '17 at 05:56

2 Answers2

0

Remove the quotation marks in if condition'$count'. This will execute the right condition.

  if($count)
  {

  }
  else {

  }
sathish R
  • 402
  • 4
  • 8
0

Problem is your code if ($count). '$count' is converted to boolean true so you always are getting same result. Remove ' from around $count

Justinas
  • 41,402
  • 5
  • 66
  • 96
  • I tried this. Now it started giving reverse output. That is now it is taking all inputs as false and returns 0. – Ganaraj Jun 17 '17 at 16:24