This code is suppose to take the images array and use its value for the name of the table. When I echo the images varaible I get kids, which is what $images[3] is set to equal, but when I put it in the query the $result2 is echoed as resource id #4. Why is it doing that?

<?php 
    $con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("photos", $con);

    echo $images[3];
    $query2="SELECT Location FROM $images[3] WHERE Pic_id='1'";
    $result2 = mysql_query($query2) or die(mysql_error());

echo $result2;

mysql_close($con);


?>

looks like you are trying to query an array, not a database table,
change '$images[3]' for the actual table name and try it.

Member Avatar for LastMitch

@garyjohnson

When I echo the images varaible I get kids, which is what $images[3] is set to equal, but when I put it in the query the $result2 is echoed as resource id #4. Why is it doing that?

I think you really need to learn how a query works. Right now, you are lost. I help you a few occasions and I notice you don't understand how to connect to the db and also understand how to create a query plus I also mention you need to touch up with the MYSQL.

Like what TonyG_cyprus mention

You can't fetch Location from an $images[3]? Is Location a column? Is $images[3] a table?

$query2="SELECT Location FROM $images[3] WHERE Pic_id='1'";

Read this:

http://www.w3schools.com/sql/default.asp

$query2="SELECT Location FROM $images[3] WHERE Pic_id='1'"; 

instead of this use something like 
    $query2="SELECT `Location` FROM `column name` WHERE `Pic_id`=1";
    if u want ot delete 3 number image then pass pic_id=3
    do not use singal or double quotes for numbers in query
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.