In the last hours I tried many codes but none of them works. I try to upload an image to my database. But the Picture doesnt show on the localhost database :(
在过去的几个小时里,我尝试了很多代码,但没有一个能够运行我尝试将图像上传到我的数据库。但图片并没有显示在localhost数据库:(
The other variables like Titel etc. are okay.
像Titel等其他变量都可以。
My Code is like this:
我的代码是这样的:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<meta charset="ISO-8859-1">
<title>Film Hinzufügen</title>
<script type=“text/javascript”>
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
</script>
<?php
if (isset($_POST['addButton'])) {
//SQL Injection defence!
//Variablen hinzufügen
$Titel = $_POST['Titel'];
$Genre = $_POST['Genre'];
$Picture = $_POST['Datei'];
$Erscheinungsjahr = $_POST['Erscheinungsjahr'];
$FSK = $_POST['FSK'];
$Filmdauer = $_POST['Filmdauer'];
$Beschreibung = $_POST['Beschreibung'];
$imgData =$_POST['Beschreibung'];
//Film hinzufügen
$con = mysql_connect("127.0.0.1","root","");
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysql_select_db("db_movie_usr");
$sqlString = "INSERT INTO t_movie (FilmTitel, Genre, Erscheinungsjahr, FSK, Filmdauer, Beschreibung, Picture) VALUES ('".$Titel."','".$Genre."','".$Erscheinungsjahr."','".$FSK."','".$Filmdauer."','".$Beschreibung."','file_get_contents($imgData)')";
if (mysql_query($sqlString)) {
header("Location:MainPage.php");
}
}
else {
print (" ");
}
?>
</head>
<body class="body2" >
<form METHOD ="POST" ACTION = "AddMovie.php">
<div style="margin:0 auto;text-align:center">
<div class="centre" >
<table class="tg">
//Add the Title, Genre etc.
</table>
<input name="Datei" type="file" size="50" accept="text/*">
<input type="Submit" name="addButton" value="Film adden" >
</div>
</div>
</form>
</body>
</html>
In my MySQL Database is a mediablob data.
在我的MySQL数据库中是一个mediablob数据。
Do you guys see my problem?
你们看到我的问题吗?
Sorry for the bad code. It is my first php code and I need to do this as my homework.
对不起代码不好意思。这是我的第一个PHP代码,我需要这样做我的作业。
1 个解决方案
#1
0
Just copy and paste this body to your code:
只需将此正文复制并粘贴到您的代码中:
<body class="body2" >
<form method="POST" action="AddMovie.php" enctype="multipart/form-data">
<div style="margin:0 auto;text-align:center">
<div class="centre" >
<table class="tg">
//Add the Title, Genre etc.
</table>
<input name="Datei" type="file" size="50" accept="text/*">
<input type="Submit" name="addButton" value="Film adden" >
</div>
</div>
</form>
</body>
Also use this php code:
也使用这个PHP代码:
<?php
if (isset($_POST['addButton'])) {
//SQL Injection defence!
//Variablen hinzufügen
$Titel = $_POST['Titel'];
$Genre = $_POST['Genre'];
$Picture = $_FILES['Datei']['tmp_name'];
$Erscheinungsjahr = $_POST['Erscheinungsjahr'];
$FSK = $_POST['FSK'];
$Filmdauer = $_POST['Filmdauer'];
$Beschreibung = $_POST['Beschreibung'];
$imgData =$_POST['Beschreibung'];
//Film hinzufügen
$con = mysql_connect("127.0.0.1","root","");
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysql_select_db("db_movie_usr");
$sqlString = "INSERT INTO t_movie (FilmTitel, Genre, Erscheinungsjahr, FSK, Filmdauer, Beschreibung, Picture) VALUES ('".$Titel."','".$Genre."','".$Erscheinungsjahr."','".$FSK."','".$Filmdauer."','".$Beschreibung."','file_get_contents($imgData)')";
if (mysql_query($sqlString)) {
header("Location:MainPage.php");
}
}
else {
print (" ");
}
?>
#1
0
Just copy and paste this body to your code:
只需将此正文复制并粘贴到您的代码中:
<body class="body2" >
<form method="POST" action="AddMovie.php" enctype="multipart/form-data">
<div style="margin:0 auto;text-align:center">
<div class="centre" >
<table class="tg">
//Add the Title, Genre etc.
</table>
<input name="Datei" type="file" size="50" accept="text/*">
<input type="Submit" name="addButton" value="Film adden" >
</div>
</div>
</form>
</body>
Also use this php code:
也使用这个PHP代码:
<?php
if (isset($_POST['addButton'])) {
//SQL Injection defence!
//Variablen hinzufügen
$Titel = $_POST['Titel'];
$Genre = $_POST['Genre'];
$Picture = $_FILES['Datei']['tmp_name'];
$Erscheinungsjahr = $_POST['Erscheinungsjahr'];
$FSK = $_POST['FSK'];
$Filmdauer = $_POST['Filmdauer'];
$Beschreibung = $_POST['Beschreibung'];
$imgData =$_POST['Beschreibung'];
//Film hinzufügen
$con = mysql_connect("127.0.0.1","root","");
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysql_select_db("db_movie_usr");
$sqlString = "INSERT INTO t_movie (FilmTitel, Genre, Erscheinungsjahr, FSK, Filmdauer, Beschreibung, Picture) VALUES ('".$Titel."','".$Genre."','".$Erscheinungsjahr."','".$FSK."','".$Filmdauer."','".$Beschreibung."','file_get_contents($imgData)')";
if (mysql_query($sqlString)) {
header("Location:MainPage.php");
}
}
else {
print (" ");
}
?>