-2
<?php
{
session_start();
include "dbconnect.php";
$target1=$_SESSION['target1'];
echo $target1;
$query = "SELECT * FROM userpictures where pictures = $target1";

$result = mysql_query($query);

var_dump($result); 
    while($row=mysql_fetch_object($result)) 
echo $row;  
    {
    $_SESSION['picid1']=$row['picid'];
    //$_SESSION['picid1']=$row->picid;

    echo $_SESSION['picid1'];

    }
}
?>

it is returning me the output as images/2101.jpgbool(false) Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource

it is giving the target1 but not the picid please help.

  • You need to check the right-hand bar, quote your variable or - even better - switch to PDO or mysqli and prepared statements. – jeroen Jan 19 '14 at 17:13

1 Answers1

0

Try this, Added ' - pictures = '$target1'

$query = "SELECT * FROM userpictures where pictures = '$target1' ";
$result = mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_object($result)) 
{
   $_SESSION['picid1']=$row->picid;       
   echo $_SESSION['picid1'];

}

Use,

$row->picid;

instead of

$row['picid']

Note: Use mysqli_* fucntions or PDO instead of mysql_* functions(deprecated)

Krish R
  • 22,583
  • 7
  • 50
  • 59