So i've been trying to make a form with an IMG uploader. The db is working and i can send the information to the database. When I tried to implement the image uploader it gives me this print: So in the form I only added the buttom to upload image, added name and on the post method i tried to upload the image before adding the data.
I did a print, and this is what it came out: Field 'imgdire' doesn't have a default value
Can someone tell me what's wrong?
PHP
**if($_SERVER["REQUEST_METHOD"] == "POST"){
// Validate album
$UploadedFileName=$_FILES['uploadimage']['name'];
if($UploadedFileName!='')
{
$upload_directory = "uploads/";
$TargetPath=time().$UploadedFileName;
if(move_uploaded_file($_FILES['files']['tmp_name'],
$upload_directory.$TargetPath)){
$QueryInsertFile="INSERT INTO album SET imgdire='$TargetPath'";
}
}
Send Information to database
// Check input errors before inserting in database
if(empty($artist_err) && empty($album_err) && empty($stock_err) &&
empty($price_err) && empty($genre_err)){
// Prepare an insert statement
$sql = "INSERT INTO album (nomealbum, stock, price, genero, nomeinter) VALUES (?, ?, ?, ?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "sssss", $param_album, $param_stock, $param_price, $param_genre, $param_artist);
// Set parameters
$param_album = $album;
$param_stock = $stock;
$param_price = $price;
$param_genre = $genre;
$param_artist = $artist;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Redirect to admin page
header("location: admin.php");
} else{
print mysqli_error($link);
echo "Algo não correu bem, por favor tente mais uma vez";
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// Close connection
mysqli_close($link);
}
FORM
<form method="POST" action="admin.php" enctype="multipart/form-data">
<div class="form-group <?php echo (!empty($artist_err)) ? 'has-error' :
''; ?>">
<label>Intérprete</label>
<input type="text" name="inter" class="form-control" placeholder="Nome do
Artista" value="<?php echo $artist; ?>">
<span class="help-block"><?php echo $artist_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($album_err)) ? 'has-error' : '';
?
>">
<label>Nome do Albúm:</label>
<input type="text" name="aname" class="form-control" placeholder="Album"
value="<?php echo $album; ?>">
<span class="help-block"><?php echo $album_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($stock_err)) ? 'has-error' :
''; ?>">
<label>Stock</label>
<input type="text" name="stocks" class="form-control" placeholder=""
value="<?php echo $stock; ?>">
<span class="help-block"><?php echo $stock_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($price_err)) ? 'has-error' : ''; ?
>">
<label>Preço</label>
<input type="text" name="prices" class="form-control" placeholder=""
value="<?php echo $price; ?>">
<span class="help-block"><?php echo $price_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($genre_err)) ? 'has-error' : ''; ?
>">
<label>Género</label>
<input type="text" name="genres" class="form-control" placeholder=""
value="<?php echo $genre; ?>">
<span class="help-block"><?php echo $genre_err; ?></span>
</div>
<div class="form-group">
<input type="file" name="uploadimage">
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</form>
</div>