-2

EDIT1 : used double quotes and single quotes but I am getting same error.

EDIT2 : same query is returning me result in mysql shell

I am selecting a row from a table.

if(!isset($_GET['title']) || !isset($_GET['user'])){
  echo "hi"; //something come here 
}
else{
 $title = $_GET['title'];
 $title = mysqli_real_escape_string($conn,$title);

 $user = $_GET['user'];
 $user = mysqli_real_escape_string($conn,$user);
 echo $title ;
 echo $user ;

 // tried giving value directly to test but no luck
 $query = "SELECT * FROM site WHERE client=\"Chaitanya\" && title=\"werdfghb\" "; 
 $result5 = mysqli_query($conn,$query) or die(mysqli_error());
 $count = mysqli_num_rows($result5);
 echo $count ;

 while($result9 = mysqli_fetch_array($result5)){ 
 $kk=$result9['url'];
 echo $kk ;
 }
 $page = $kk; 
 include ( 'counter.php');
 addinfo($page);
}

In my database there is a row with columns title and client and the values I entered are in that row but when I echo count(no of rows) it is showing zero.

Is there anything wrong with code ?

3 Answers3

1

The error you are getting is due to the line

$page = $kk;

in this code $kk is not declared previously. The defined $kk is in the while loop scope.

declare the variable like this in the outer scope from the while loop

...
$kk = null;
while($result9 = mysqli_fetch_array($result5)) { 
    $kk = $result9['url'];
    echo $kk ;
}
$page = $kk; 
...

Error on Fetching Data

You have to crack you SQl into smaller pieces and test the code like this.

  1. run the query SELECT * FROM site without any where and get the count
  2. run the query SELECT * FROM site WHERE client='Chaitanya' and get the count
  3. SELECT * FROM site WHERE title='werdfghb' and check the count
  4. Then run the whole query

And see the results. This way u can find out in where the issue is in your SQL code. I prefer you use the mysql client to execute this queries

Faraj Farook
  • 14,385
  • 16
  • 71
  • 97
0

As I pointed out in my comment, $kk is undefined in the $page = $kk;, since it is declared in the while loop.

Do something like:

$kk = '';   //can also do $kk=NULL; if you want.
while($result9 = mysqli_fetch_array($result5)) { 
    $kk=$result9['url'];
    echo $kk ;
}
$page = $kk; 
JClaspill
  • 1,725
  • 19
  • 29
  • got rid of error but my problem is that if there is a row with the values i have given , i am not getting any result , i am getting 0 if use mysqli_num_rows – Naga Inquisitive Apr 09 '15 at 21:07
0

try this one

$client = "Chaitanya";

$title = "werdfghb";

$query="SELECT * FROM site WHERE client='".$client."' and title='".$title."' ";

you can also use this

$query="SELECT * FROM site WHERE client={$client} and title={$title} ";