代码操作
<?php
$link = mysqli_connect("localhost", "root", "usbw", "homelessons");
mysqli_set_charset($link, "utf8");
?>
<?php
if(isset($_POST["add"])){
$name = $_POST["name"];
$price = $_POST["price"];
$img = "";
$date = $_POST["date"];
if(isset($_FILES["image"])){
$img_folder = "";
$image_name = $_FILES["image"]["name"];
$img = $img_folder . $image_name;
$file_path = "/img" . $img;
move_uploaded_file($_FILES["image"]["tmp_name"], $file_path);
}
$sql_add = "
INSERT INTO `lesson_first`
(name, price, img, date)
VALUES
('$name', '$price', '$img', '$date')
";
$func = mysqli_query($link, $sql_add);
if($func == True){
header("Location: show.php");
}
else{
echo "Something went wrong";
mysqli_error($link);
}
}
?>
代码形式
<form action="add.php" method="post" enctype="multipart/form-data">
<label for="name">name</label><br>
<input type="text" name="name"><br><br>
<label for="price">price</label><br>
<input type="number" name="price" rows="10" cols="46"><br><br>
<input type="file" name="image"><br><br>
<input type="date" name="date"><br><br>
<input type="submit" name="add">
</form>
我有将从表单接收到的信息添加到sql数据库的代码,并且看来我写的都正确,因为我没有任何错误,但是我得到了另外的提示:“出了点问题”,所以我不知道在哪里我的错误
尝试一下:
if(! $func){
echo "Something went wrong";
mysqli_error($link);
}else{
header("Location: show.php");
}