| | #1 |
| Warrior Member Join Date: 2011
Posts: 24
Thanks: 3
Thanked 0 Times in 0 Posts
|
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> |
| |
| | #2 |
| VIP Warrior War Room Member Join Date: 2006 Location: , , USA.
Posts: 1,795
Thanks: 70
Thanked 287 Times in 259 Posts
|
You're not selecting it from the table: $data = mysql_query("SELECT `path` FROM people ") |
| |
| | #3 |
| Opal Infotech Join Date: 2010 Location: India
Posts: 80
Thanks: 0
Thanked 3 Times in 3 Posts
|
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. |
| |
|
| Bookmarks |
| Tags |
| image, mysql, path |
| |