i am adding elements to my db and the elemtents which have been add will be displayed on a different page. i am using an upload page which creates a thumb nail of an uploaded image and then stores the path for this image in a variable called $thumb_name. the code i have used to enter the image into the db is

include "db.php";

$con = mysql_pconnect("$dbhost","$dbusername","$dbpasswd") 
	or die ("QUERY ERROR: ".mysql_error());

$db = mysql_select_db("$database_name", $connection)
	or die("QUERY ERROR: ".mysql_error());
			
		// Create table in $database_name database
		mysql_select_db("$database_name", $connection);
			$sql = "CREATE TABLE images 
				(imageID int NOT NULL AUTO_INCREMENT, Broad1 varchar(50), Broad2 varchar(50), Broad3 varhar(50))";

		mysql_query("INSERT INTO images (Broad1) VALUES ('$thumb_name')");
?>

and the code to display the image on the next page looks like this

<?php
				include"db.php";

				$result = mysql_query("SELECT * FROM images WHERE 'Broad1'='$thumb_name'");
  					{
  					echo $row['Broad1'];
  					echo "<br />";
					}
			?>

Everything is correct.. But this is wrong.

$result = mysql_query("SELECT * FROM images WHERE 'Broad1'='$thumb_name'");
{
echo $row;
echo "<br />";
}
?>

This should be

$result = mysql_query("SELECT * FROM images WHERE 'Broad1'='$thumb_name'");
$row= mysql_fetch_array($result);
echo $row['Broad1'];
echo "<br />";
?>

And

$result = mysql_query("SELECT * FROM images WHERE 'Broad1'='$thumb_name'");

Should be

$result = mysql_query("SELECT * FROM images WHERE Broad1='$thumb_name'");

No quotes around Broad1.

And

$result = mysql_query("SELECT * FROM images WHERE 'Broad1'='$thumb_name'");

Should be

$result = mysql_query("SELECT * FROM images WHERE Broad1='$thumb_name'");

No quotes around Broad1.

Ah! correct.. I couldn't spot that one!

commented: very helpful +1

i have correct the few lines of code which were wrong but it is now saying that the table i have created does not exist. the code i have used to create the table is

include "db.php";

$con = mysql_pconnect("$dbhost","$dbusername","$dbpasswd") 
    or die ("QUERY ERROR: ".mysql_error());

$db = mysql_select_db("$database_name", $connection)
    or die("QUERY ERROR: ".mysql_error());

        // Create table in $database_name database
        mysql_select_db("$database_name", $connection);
            $sql = "CREATE TABLE images (imageID int NOT NULL AUTO_INCREMENT, Broad1 varchar(50), Broad2 varchar(50), Broad3 varhar(50))";

        mysql_query("INSERT INTO images (Broad1) VALUES ('$thumb_name')");

were have i gone wrong?

You aren't executing the create table query.

$sql = "CREATE TABLE images (imageID int NOT NULL AUTO_INCREMENT, Broad1 varchar(50), Broad2 varchar(50), Broad3 varhar(50))";

After this, you need to have mysql_query($sql);

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.