0

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 />";
					}
			?>
3
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by nav33n
0

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 />";
?>
0

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.

1

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!

Votes + Comments
very helpful
0

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?

Edited by mike_2000_17: Fixed formatting

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.