PHP data cannot be inserted into the database
P粉655825841
P粉655825841 2022-03-30 15:01:59
0
3
1058
<?php
    require_once('../connect.php');
    mysqli_query("set names utf-8");
    //把传递过来的信息入库,在入库之前对所有的信息进行校验。
    print_r($_POST);
    $title = $_POST['title'];
    $times = $_POST['times'];
    $source = $_POST['source'];
    $column = $_POST['column'];
    $content = $_POST['content'];
    $dateline = time();

    if(!isset($_POST['title']) || empty($_POST['title'])) {
        echo "<script>alert('标题不能为空'); window.location.href='article.add.php'</script>";
    }elseif(!isset($_POST['column']) || empty($_POST['column'])){
        echo "<script>alert('栏目不能为空'); window.location.href='article.add.php'</script>";
    }else{
        $con = mysqli_connect("localhost", "root", "root", "info"); //准备SQL语句,查询用户名
        $insertsql = "SELECT info FROM article WHERE title = '$title'"; //执行SQL语
        $ret = mysqli_query($con,$insertsql);
       
        if (!$ret) {
            die('Query failed');
        }
      }
 ?>

P粉655825841
P粉655825841

reply all(2)
autoload

Troubleshoot, first check if there is any problem with the connection, and then check the problem with the query statement

P粉655825841

It’s my mysqli_query that always returns false

  • reply Why is this? I still can’t find the reason.
    P粉655825841 author 2022-03-30 15:04:22
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template