<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>
I talked to 'PHP expert' for hours, he couldn't seem to figure out my problem. My inputs aren't submitting to my db, title/description. I can use
$title = $_POST['dsfasfddsfa'];
and it will insert that, but I can't insert what users enter into the field. When I added
$title = $_POST['title']; & $description = $_POST['description'];
I get unidentified index on title and description, that's why I added the if statements at the top of my php code.
I read on a website it was suppose to remove them, I thought it'd work once they were gone, I was wrong. Nothing worked when I did that. I can get the video to upload, but the fields don't work. Any and all help is great! Thanks in advance.I also used submit as the $_POST in the two if statements at the start if the php code, didn't work.
Try to do an simple version david like in this example first.
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.
Then later step by step you will change the things that you want.
At the end will be working.