我的php文件在localhost或webhost上都不工作,mysql\u connect有问题吗?

ej83mcc0  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(280)

我的php文件在localhost或webhost上都不工作,我的mysql\u connect有问题吗?

still not fixed, this is what I did base on your reply:

<?php

error_reporting(E_ALL);

//first get the post variables on the page
$region=$_POST['region'];
$province_of_provider=$_POST['province_of_provider'];

$con=mysqli_connect('localhost','gengon4_tesda','gengon4_tesda','gengon4_tesda');
if(!$con)
{
    die('Could not connect:'.mysql_error());
}

//mysql_select_db('gengon4_tesda',$con);

$query="INSERT INTO `details` (`id`, `date_of_entry`, `region`, `province_of_provider`) VALUES (NULL, 'CURRENT_TIMESTAMP(6).000000', '$region', '$province_of_provider')";

if(!mysql_query($query,$con))
{
    die('Error in inserting records'.mysql_error);
}else
{
    echo "Data Inserted";
}

echo mysql_errno($con) . ": " . mysql_error($con) . "\n";

?>

我没有找到任何有关错误的信息。你知道怎么解决这个问题吗?

scyqe7ek

scyqe7ek1#

首先启用php.ini中的display\u errors作为 display_errors = On 或者在php文件中设置为 ini_set("display_errors", 1); 这样你就应该知道你的代码有什么问题了。
代码修改: $con=mysqli_connect('localhost','gengon4_tesda','gengon4_tesda','gengon4_tesda'); 你曾经 mysqli_connect 连接数据库 if(!mysql_query($query,$con)) 'mysql'u查询到正在运行的查询。请确保在您的代码中使用相同的mysqli或mysql方法。

vom3gejh

vom3gejh2#

不要使用 mysql_* 功能。始终使用 mysqli_* 功能。
启用按命令显示错误: error_reporting(E_ALL); (源代码的第一行)
然后通过以下方式显示错误: echo mysql_errno($con) . ": " . mysql_error($con) . "\n"; (密苏里州)
那你就知道怎么了

相关问题