<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专家&#39;进行了交谈。几个小时,他似乎无法弄清楚我的问题。我的输入没有提交到我的数据库,标题/描述。我可以用
$title = $_POST['dsfasfddsfa'];
它会插入,但我无法插入用户输入的字段。当我添加
$title = $_POST['title']; & $description = $_POST['description'];
我在标题和描述上得到了不明的索引,这就是我在php代码顶部添加if语句的原因。
我在网站上看到它想要删除它们,我认为它们一旦消失就会工作,我错了。当我这样做时,没有任何效果。我可以上传视频,但这些字段不起作用。任何和所有帮助都很棒!提前谢谢。如果php代码没有工作,我也在开头的两个if语句中使用submit作为$ _POST。
答案 0 :(得分:0)
首先尝试像这个例子那样做一个简单版本的david。
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.
然后,您将逐步改变您想要的东西。
最后将会有效。