[英]HTML form input errors PHP
<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語句的原因。
我在一個網站上讀到了要刪除它們的信息,我以為一旦它們消失就可以了,我錯了。 當我這樣做時,什么都沒有。 我可以上傳視頻,但是這些字段不起作用。 任何幫助都很棒! 在此先感謝,我也使用了提交作為$ _POST在兩個if語句中,如果PHP代碼不起作用的話。
首先嘗試制作一個簡單的大衛版本,如本例所示。
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.
然后,您將逐步逐步更改所需的內容。
最后會工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.