search

Home  >  Q&A  >  body text

PHP data cannot be inserted into the database

<?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粉655825841P粉655825841977 days ago1048

reply all(3)I'll reply

  • autoload

    autoload2022-03-31 09:32:44

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

    reply
    0
  • P粉655825841

    P粉6558258412022-03-30 15:03:26

    It’s my mysqli_query that always returns false

    reply
    0
  • P粉655825841

    Why is this? I still can’t find the reason.

    P粉655825841 · 2022-03-30 15:04:22
  • Cancelreply