I am a beginner in PHP. I got a task to create an admin panel and upload an image to database and it should display on another page. Now I tried but the result is coming on the same page. And some error is also present there.
" Deprecated: `mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp64\www\Image Upoad PHP\Img Up [www.students3k.com]\Upload photos\config.php on line 7".`
Code:
index.html
<form action="addexec.php" method="post" enctype="multipart/form- data" name="addroom"> Select Image: <br /> <input type="file" name="image" class="ed"><br /> Caption<br /> <input name="caption" type="text" class="ed" id="brnu" /> <br /> <input type="submit" name="Submit" value="Upload" id="button1" onclick="a.php"/>
<?php include('config.php'); $result = mysql_query("SELECT * FROM photos"); while($row = mysql_fetch_array($result)) { echo '<div id="imagelist">'; echo '<p><img src="'.$row['location'].'"></p>'; echo '<p id="caption">'.$row['caption'].' </p>'; echo '</div>'; } ?>
2.addexce.php
<?php
include('config.php');
if (!isset($_FILES['image']['tmp_name'])) {
echo "";
}else{
$file=$_FILES['image']['tmp_name'];
$image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name= addslashes($_FILES['image']['name']);
move_uploaded_file($_FILES["image"]["tmp_name"],"photos/" . $_FILES["image"]["name"]);
$location="photos/" . $_FILES["image"]["name"];
$caption=$_POST['caption'];
$save=mysql_query("INSERT INTO photos (location, caption) VALUES ('$location','$caption')");
header("location: index.php");
exit();
}
?>
3.config.php
<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "root";
$mysql_database = "photoupload";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or
die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
?>
in addexce.php
file
with header header("location: index.php");
we donot have that feasbility.
so try below
replace header("location: index.php");
with echo '<script>window.open("here add total url","_blank");</script>';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.