我按照教程制作了一个登录系统,并且学到了很多东西。但是现在我正在尝试提供视频共享服务,而我尝试插入数据库中的所有信息实际上都没有。我想我已经正确编码了,但是似乎没有用。
我正在使用xampp并使用PHP和Apache。我尝试更改一些代码,甚至重新创建了我要向其中插入数据的表。
// All the database code
require 'dbh.inc.php';
if(isset($_POST["video-submit"])) { // Where the user presses the submit
// Getting the variables
$file = $_FILES['video'];
$filename = $file['name'];
$fileexp = explode('.', $filename);
$fileext = strtolower(end($fileexp));
$title = $_POST['title'];
$desc = $_POST['desc'];
$author = $_SESSION['userid'];
$sql = "SELECT videoid FROM videos WHERE videoid = ?"; // Finds the videoid
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) { // Error checking
header("location: ../upload.php?upload=fail&reason=sqlerror&title=".$title."&desc=".$desc);
exit();
} else {
mysqli_stmt_bind_param($stmt, "s", $videoid);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$result = mysqli_stmt_num_rows($stmt);
if ($result > 0) { // Checking if $videoid already exists
header("location: ../upload.php?upload=fail&reason=sqlerror&title=".$title."&desc=".$desc);
exit();
} else {
$sql = "INSERT INTO videos (videoid, video, title, description, author, views, likes, dislikes) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: ../upload.php?upload=fail&reason=sqlerror&title=".$title."&desc=".$desc);
exit();
} else {
$views = $likes = $dislikes = 0;
$video = $videoid.".".$fileext;
$filedest = "../videos/".$videoid;
move_uploaded_file($filetmp, $filedest);
mysqli_stmt_bind_param($stmt, "sssssiii", $videoid, $video, $title, $desc, $author, $views, $likes, $dislikes);
mysqli_stmt_execute($stmt);
header('location: /watch.php?v='.$video);
exit();
}
}
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
我希望将数据插入数据库,但是在代码运行后进行检查时,没有任何迹象。该注册代码可以完美运行。请告诉我这是否是一个愚蠢的错误。