我是PHP的初学者。我有一个任务是创建一个管理面板并将图像上传到数据库,它应该显示在另一个页面上。现在我尝试了但结果却出现在同一页面上。 那里也出现了一些错误。
" 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".`
代码:
的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();
}
&GT;
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");
?>
答案 0 :(得分:0)
标题addexce.php
我们不具备这种可行性。
所以请尝试以下
替换header("location: index.php");
header("location: index.php");