"SQL error" no puedo subir imagenes
Publicado por Federico Cando (3 intervenciones) el 26/02/2020 21:24:41
estaba tratando de subir una galeria de imagenes con PHP y SQL, pero no puedo subir imagenes por que siempre salta un error cuando inicio una funcion especial, no soy mut bueno programando y todo lo que se lo vi en Youtube, trate de fijarme en el video pero no tenia respuesta. Dejo el codigo, pero creo que el problema esta cuando inicia mysqli_stmt_prepare.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
if (isset($_POST['submit'])) {
$newFileName = $_POST['filetitle'];
if (empty($newFileName)) {
$newFileName = "gallery";
} else {
$newFileName = strtolower(str_replace(" ", "-", $newFileName));
}
$imageTitle = $_POST['filetitle'];
$file = $_FILES["file"];
$fileName = $file["name"];
$fileType = $file["type"];
$fileTempName = $file["tmp_name"];
$fileError = $file["error"];
$fileSize = $file["size"];
$fileExt = explode(".", $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array("svg");
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 2000000) {
$imageFullName = $newFileName . "." . uniqid("", true) . "." . $fileActualExt;
$fileDestination = "../img" . $imageFullName;
include_once "dbh.inc.php";
if (empty($imageTitle)) {
header("Location: ../gallery.php?upload=empty");
exit();
} else {
$query = "SELECT * FROM gallery ORDER BY gallery_order DESC";
$statement = mysqli_stmt_init($connection);
if (!mysqli_stmt_prepare($statement, $query)) {
echo "SQL Error!";
} else {
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$rowCount = mysqli_num_rows($result);
$setImageOrder = $rowCount + 1;
$sql = "INSERT INTO galley (tittleGallery, ImgFullNameGallery, orderGalley) VALUES (?, ?, ?);";
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL statement failed!";
} else {
mysqli_stmt_bind_param($stmt, "ssss", $imageTitle, $imageFullName, $setImageOrder);
mysqli_stmt_execute($stmt);
move_uploaded_file($fileTempName, $fileDestination);
header("Location ../gallery.php?upload-success");
}
}
}
} else {
echo "You have an Error!";
exit();
}
}
}
}
else{
echo "You need to upload SVG Files!";
exit(); }
?>
Valora esta pregunta


0