neuen Gästebucheintrag anlegen





real_escape_string($_POST['Autor']); $Text = $db->real_escape_string($_POST['Text']); $Datum = $_POST['Datum']; $sql1 = 'INSERT INTO gb (ID, Autor, Text, Datum) VALUES (NULL, "' . $Autor . '", "' . $Text . '", "' . $Datum . '");'; $stmt1 = $db->prepare($sql1); if (!$stmt1) { die ('Es konnte kein SQL-Query vorbereitet werden: ' . $db->error); } if (!$stmt1->execute()) { die ('Query konnte nicht ausgeführt werden: ' . $stmt1->error); } $sql2 = 'SELECT last_insert_id()'; $result2 = $db->query($sql2); $last = $result2->fetch_assoc(); $id = $last['last_insert_id()']; $uploaddir = '../img/umgebung/gb/'; $uploadfile = $uploaddir . $_FILES['Foto']['name']; move_uploaded_file($_FILES['Foto']['tmp_name'], $uploadfile); $src = imagecreatefromjpeg($uploadfile); list($width, $height) = getimagesize($uploadfile); if ($height > $width) { $newheight = 200; $newwidth = ($width / $height) * 200; } else { $newwidth = 200; $newheight = ($height / $width) * 200; } $tmp = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); $filename = $uploaddir . $id . ".jpg"; imagejpeg($tmp, $filename, 80); imagedestroy($src); imagedestroy($tmp); unlink($uploaddir . $_FILES['Foto']['name']); } echo 'Zurück zur Übersicht'; }