Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 6th May 2014, 08:36 AM   #1
Warrior Member
 
Join Date: 2011
Posts: 24
Thanks: 3
Thanked 0 Times in 0 Posts
Lightbulb
Image path in mysql
Share on: 
fb share twitter share gplus share more share

I wrote this script to upload images to a folder in my server and add the image path and description to mysql table. I tried retriving the images and descriptions from the database, the images will be displayed, but the description will not.



<?php
$con=mysql_connect('localhost','****','*******') or die(mysql_error());
$vb=mysql_select_db('test');
$config='Real Php';
?>
<!doctype html><html>
<head>
<title>php oop</title>
<meta charset="utf-8">

</head>
<body><h1 style="color:#191970"><?php echo $config ?></h1>

<form action="get.php" method="POST" enctype="multipart/form-data">
<label for="file">File</label><br />


<input type="file" name="file"/><br />
<input type="text" name="cap" size="40" />
<input type="submit" value="upload" name="sade"/><br />
</form>

<?php
$folder="images/";
$upload = $_POST['sade'];
$file = $_POST['file'];
$cap=$_POST['cap'];
if(isset($upload))
{
move_uploaded_file($_FILES['file']['tmp_name'], "$folder".$_FILES['file']['name']);
echo $_FILES['file']['name']." is been added";
$path=$_FILES['file']['name'];
echo $path=$_FILES['file']['name'];

$insert=mysql_query("insert into people(path,caption) values('$path','$cap') ");

if($result) { echo "Image name saved into database"; }
else {

//Gives and error if its not
echo mysql_error();
}
}

else{echo "Error";}


?>

The above is upload images.







The code below is to fetch images and description but it fetches only the iamge, what do you think could be wrong?

<?php
$con=mysql_connect('localhost','*****','*******') or die(mysql_error());
$vb=mysql_select_db('test');
?>
<!doctype html><html>
<head> <link rel="stylesheet" type="text/css" href="main.css" />
<link rel="stylesheet" href="main.css" type="text/css" media="screen" />
<title>Real php | <?php echo $config; ?></title>
<meta charset="utf-8">
<style type="text/css">
a:hover,a:active,a:link{text-decoration:none;}
</style>
</head>
<body>
<h2>Finally</h2>
<?php

$data = mysql_query("SELECT `path` FROM people ") or
die(mysql_error());
//Puts it into an array
$file_path = 'http://localhost/green/images/';

while($row = mysql_fetch_assoc( $data ))
{//Outputs the image and other data

$src=$file_path.$row['path'];
echo "<img src=".$src."> <br>";
echo $row['caption'].'<br/>';
echo $row['caption'];
}
if(!$row){echo mysql_error();}


?>
</body>
</html>
heroecitadel is offline  
Unread 6th May 2014, 11:32 AM   #2
VIP Warrior
War Room Member
 
Join Date: 2006
Location: , , USA.
Posts: 1,795
Thanks: 70
Thanked 287 Times in 259 Posts
Default
Re: Image path in mysql
Share on: 
fb share twitter share gplus share more share

You're not selecting it from the table:

$data = mysql_query("SELECT `path` FROM people ")
KirkMcD is offline  
Unread 20th May 2014, 07:30 AM   #3
Opal Infotech
 
Join Date: 2010
Location: India
Posts: 80
Thanks: 0
Thanked 3 Times in 3 Posts
Default
Re: Image path in mysql
Share on: 
fb share twitter share gplus share more share

It’s very simple, You are inserting both the thing image name and the description, But when you fetching the data at that time you are just fetching the image name as ‘path’but not the description which you stored in the caption.
You have to write
$data = mysql_query("SELECT * FROM people ") OR
$data = mysql_query("SELECT `path`,`caption` FROM people ")
And than you can fetch as array and display.
jigney is offline  
Closed Thread


Bookmarks

Tags
image, mysql, path


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 06:36 AM.