我的插入查询不正常。数据库名称正确,表名正确

<?php
$con = mysql_connect("localhost", "root", "") or die(mysql_errno());
$database = mysql_select_db("cms", $con) or die(mysql_errno());
if (isset($_POST['sub'])) {
    $pt = $_POST['P-title'];
    $pd = $_POST['p-dis'];
    $q  = "insert into pages(P_Title,P-Description) values('$pt','$pd')";
    if (mysql_query($q)) {
        echo "<script>alert ('Inserted successfully')</script>";
        echo "<script>window.open('Admin-Panal.php','_self')</script>";
    } else {
        echo "query not working";
    }
}
?>

the best way you can do by creating a seperate configuration file so that any changes in future can be made easily.

config.php

<?php
$localhost = "localhost";
$user = "root";
$password = "";
$database = "form1"; // your database name
//$con = mysqli_connect("localhost","my_user","my_password","my_db");
$conn = mysqli_connect($localhost,$user,$password,$database);

// Check connection
if (mysqli_connect_errno())
  {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  echo "connection sucessful";
?>

include this file by calling require_once "config.php"; the in which you are working right now

workingfile.php

     <?php  
           require_once "config.php";
            if(isset($_POST['sub']))

            {
                $pt = $_POST['P-title'];
                $pd = $_POST['p-dis'];
                $tableName = "user_information";//your table name
$query = "INSERT INTO $tableName (P_Title,P-Description) VALUES('".$pt."','".$pd."')";                           
                if ($conn->query($query) === TRUE) {
                    echo "New record created successfully";
                } else {
                    echo "Error: " . $query . "<br>" . $conn->error;
                }

                $conn->close();


            }
         ?>