Image path in mysql
<?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>
-
KirkMcD -
Thanks
{{ DiscussionBoard.errors[9168054].message }} -
-
jigney -
Thanks
{{ DiscussionBoard.errors[9205218].message }} -