<form action="index.php" name="Submit_Form" method="post" enctype="multipart/form-data" id="upload" class="upload">
<fieldset>
<legend>Upload</legend><br/>
Title: <input type="text" name="title" id="name" class="name" required> <br/><br/>
<textarea name="description" rows="6" cols="35" maxlength="120"></textarea><br/>
<input type="file" id="file" name="file[]" required multiple><br/>
<input type="submit" id="submit" name="submit" value="Upload">
</fieldset>
<div class="bar">
<span class="bar-fill" id="pb"><span class="bar-fill-text" id="pt"></span></span>
</div>
<div id="uploads" class="uploads">
Uploaded file links will appear here.
</div>
<?php
if (isset($_POST['title'])) {
$title = $_POST['title'];
}
if (isset($_POST['description'])) {
$description = $_POST['description'];
}
$dbhost = "localhost";
$dbname = "blog";
$dbuser = "root";
$dbpass = "";
// database connection
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// query
$stmt = $conn->prepare("INSERT INTO videos (title,description) VALUES (?,?)");
$stmt->bind_param("ss", $title, $description);
$stmt->execute();
$stmt->close();
$conn->close();
?>
<script src="upload.js"></script>
<script>
document.getElementById('submit').addEventListener('click', function(e) {
e.preventDefault();
var f = document.getElementById('file'),
pb = document.getElementById('pb'),
pt = document.getElementById('pt');
blog.uploader({
files: f,
progressBar: pb,
progressText: pt,
processor: 'uploads.php',
finished: function(data) {
var uploads = document.getElementById('uploads'),
succeeded = document.createElement('div'),
failed = document.createElement('div'),
anchor,
span,
x;
if(data.failed.length) {
failed.innerHTML = '<p>This item failed to upload:</p>';
}
uploads.textContent = '';
for(x = 0; x < data.succeeded.length; x = x + 1) {
anchor = document.createElement('a');
anchor.href = 'uploads/' + data.succeeded[x].file;
anchor.textContent = data.succeeded[x].name;
anchor.target = '_blank';
succeeded.appendChild(anchor);
}
for(x = 0; x < data.failed.length; x = x + 1) {
span = document.createElement('span');
span.textContent = data.failed[x].name;
failed.appendChild(span);
}
uploads.appendChild(succeeded);
upload.appendChild(failed);
},
error: function() {
console.log('Not working');
}
});
});
</script>
</form>
</body>
</html>
我和"PHP专家"谈了几个小时,他似乎无法解决我的问题。我的输入没有提交到我的数据库,标题/描述。我可以用
$title = $_POST['dsfasfddsfa'];
,它会插入,但是我不能插入用户输入的内容。当我添加
$title = $_POST['title']; & $description = $_POST['description'];
我在标题和描述上得到了未识别的索引,这就是为什么我在php代码的顶部添加了if语句。
我在一个网站上看到它应该删除它们,我以为一旦它们消失就会起作用,我错了。当我这样做的时候,没有任何效果。我可以上传视频,但田地坏了。任何帮助都是伟大的!提前感谢。如果php代码不工作,我还在开始的两个if语句中使用submit作为$_POST。
试着先做一个简单的版本,就像这个例子。
http://php.net/manual/es/tutorial.forms.php<form action="action.php" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>
.
Hi <?php echo htmlspecialchars($_POST['name']); ?>.
You are <?php echo (int)$_POST['age']; ?> years old.
然后一步一步地改变你想要的东西。
最后将会工作。