We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,408 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

php mysql query wont work properly

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);


?>
4
Contributors
3
Replies
1 Week
Discussion Span
4 Months Ago
Last Updated
4
Views
garyjohnson
Junior Poster
142 posts since Aug 2012
Reputation Points: 14
Solved Threads: 1
Skill Endorsements: 0

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

TonyG_cyprus
Posting Whiz
315 posts since Dec 2009
Reputation Points: 46
Solved Threads: 40
Skill Endorsements: 2

@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

LastMitch
Industrious Poster
4,212 posts since Mar 2012
Reputation Points: 134
Solved Threads: 336
Skill Endorsements: 45
$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
arti18
Posting Whiz in Training
207 posts since Dec 2012
Reputation Points: 2
Solved Threads: 25
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0843 seconds using 2.71MB