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

时间:2016-09-17 12:11:51

标签: php html

<?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";
    }
}
?>

1 个答案:

答案 0 :(得分:0)

您可以通过创建单独的配置文件来实现最佳方式,以便将来可以轻松进行任何更改。

<强>的config.php

<img src="<?php echo get_template_directory_uri(); ?>/images/image.jpg">  

通过调用require_once&#34; config.php&#34;;包含此文件你现在在哪里工作

<强> workingfile.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";
?>