0

When i run this query images are displaying from php correctly.

<?php
mysql_connect("localhost", "root", "");
mysql_select_db("dawat");
$submit=$_GET['str'] ;
$sql = mysql_query("SELECT * FROM searchengine WHERE pagecontent LIKE '%$_GET%' ");    
while($row=mysql_fetch_array($sql)) {
echo "<img src=image.php?pagecontent=".$row['pagecontent']." />";
}
?>

And code of image.php:

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = mysql_connect("localhost","root","");
if(!$conn)
{
echo mysql_error();
}
$db = mysql_select_db("dawat",$conn);
if(!$db)
{
echo mysql_error();
}
$pagecontent = $_GET['pagecontent'];
$q = "SELECT pageurl FROM searchengine where pagecontent='$pagecontent'";
$sql = mysql_query("$q",$conn);
if($sql)
{
$row = mysql_fetch_array($sql);
echo $row['pageurl'];
}
else
{
echo mysql_error();
}
?>

And when i run same code of above just few changes in search script:

<?php
mysql_connect("localhost", "root", "");
mysql_select_db("dawat");
$submit=$_GET['str'] ;
$sql = mysql_query("SELECT pageurl, BIT_COUNT(pagecontent^'$submit') 
FROM searchengine WHERE pagecontent < 20 ORDER BY pagecontent ASC;
") or die(mysql_error());
while($row=mysql_fetch_array($sql)) {
echo "<img src=image.php?pagecontent=".$row['pagecontent']." />";
}
?>

It is showing errors that undefined index:pagecontent and also not showing images.Please help and thanks in advance.

1
  • Are you sure that your changed SQL has return value ? Commented Aug 22, 2014 at 4:58

2 Answers 2

3

In your query

$sql = mysql_query("SELECT pageurl, BIT_COUNT(pagecontent^'$submit') 
FROM searchengine WHERE pagecontent < 20 ORDER BY pagecontent ASC;
") or die(mysql_error());

You are not fetching the column pagecontent and is trying to access it in

echo "<img src=image.php?pagecontent=".$row['pagecontent']." />";
                                                   ^

So change your query to,

$sql = mysql_query("SELECT pageurl,pagecontent, BIT_COUNT(pagecontent^'$submit') 
FROM searchengine WHERE pagecontent < 20 ORDER BY pagecontent ASC;
") or die(mysql_error());
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much.I worked.You don't know how much i have troubled for this..Thank you.
1

Try it and get print value from $sql.. you will get idea from how to return it..

$sql = mysql_query("SELECT pageurl,pagecontent, BIT_COUNT(pagecontent^'$submit') 
FROM searchengine WHERE pagecontent < 20 ORDER BY pagecontent ASC;
") or die(mysql_error());

1 Comment

Thank you so much.I worked.You don't know how much i have troubled for this..Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.