我只是一个初学者,需要你的帮助。
我制作了一个上传脚本(MySQL),但需要上传图像/文件。我不知道在哪里放置代码的上传部分。
这是我的代码:
<?php
error_reporting(E_ALL);
mysql_connect("xx.xx.nl","xx","xxxx") or
die("Kan geen verbinding maken met de server!");
mysql_select_db("xxx") or die("Kan de ingevoerde database niet vinden");
if ($_POST){
// file upload code
if (is_uploaded_file($_FILES['img']['tmp_name'])) {
move_uploaded_file($_FILES['img']['tmp_name'], 'test/upload/'.$_FILES['img']['name']);
}
$query = "INSERT INTO product (
naam,
id,
titel,
druk,
img,
beschrijving)
VALUES ('".$_POST['naam']."',
'".$_POST['id']."',
'".$_POST['titel']."',
'".$_POST['druk']."',
'".$_FILES['img']['name']."',
'".$_POST['beschrijving']."')";
echo $query;
mysql_query($query) or die("Kan niet invoegen.<br>". mysql_error());
header("location:login.php");
exit;
}
?>
<table>
<form action='voegtoe.php' method='POST' enctype='multipart/form-data'>
<tr><td> Auteur : </td><td> <select name="naam"><option value="0">Selecteer</option>
<?php
include("../includes/config.php");
$get=mysql_query("SELECT naam FROM auteurs");
while($row = mysql_fetch_assoc($get))
{
?>
<option value = "<?php echo($row['naam'])?>" >
<?php echo($row['naam']) ?>
</option>
<?php
}
?>
</select></tr></td>
<tr><td> Titel : </td><td> <input style="background-color: #757474;" type="text"
name="titel"> </tr></td>
<tr><td> Druk : </td><td> <input style="background-color: #757474;" type="text" name="druk"> </tr></td>
<tr><td> Beschrijving : </td><td> <textarea style="background-color: #757474;" cols="25" rows="5" name="beschrijving"></textarea> </tr></td>
<tr><td> Afbeelding : </td><td> <input style="background-color: #757474;" type="file" name="img" accept="image/jpg,image/gif,image/png" /> </tr></td>
<tr><td> </td><td> <input class="button" type="submit" value="Opslaan" > </tr></td>
</form>
</table>
代码已更新