php脚本错误i mysql连接错误

php脚本错误i mysql连接错误,php,mysql,Php,Mysql,这是我的剧本 <?php define('HOST','databases.000webhost.com/localhost'); define('USER','id847165_user'); define('PASS','qwertyuiop'); define('DB','id847165_db'); $con = mysqli_connect(HOST,USER,PASS,DB); $name = $_POST['name']; $address =

这是我的剧本

<?php
  define('HOST','databases.000webhost.com/localhost');
  define('USER','id847165_user');
  define('PASS','qwertyuiop');
  define('DB','id847165_db');
  $con = mysqli_connect(HOST,USER,PASS,DB);

  $name = $_POST['name'];
  $address = $_POST['address'];

    $sql = "insert into Persons (name,address) values ('$name','$address')";
  if(mysqli_query($con,$sql)){
    echo 'success';
  }
  else{
    echo 'failure';
  }
  mysqli_close($con);
?>


有人能帮我更正吗?

使用
localhost
作为连接主机名。(仅当您的文件位于000webhost服务器中时

改变
'databases.000webhost.com/localhost'

'localhost'

使用
localhost
作为连接主机名。(仅当您的文件位于000webhost服务器中时。

改变
'databases.000webhost.com/localhost'

'localhost'

如果您的站点托管在000webhost上

forget your 00wh info, when you create your database, you have to give it a name, username, and password, then you'll see them in the page,
$user="";<---- User name you entered when making the database(prefixed with "a8314628_"),
$password="";<---- password you entered when making the database,
$database="a8314628_forum";<---- looks like you've got this part right,
$hostname="";<---- it will be shown where i mentioned above.,
click the MySql button, ALL the info is right there, if you've set up the db.

here's an example only:
$user="a8314628_something";
$password="password";
$database="a8314628_forum";
$hostname="mysql2.000webhost.com"
忘记你的00wh信息,当你创建数据库时,你必须给它一个名称、用户名和密码,然后你会在页面上看到它们,

$user=”“ 如果您的站点托管在000webhost上

forget your 00wh info, when you create your database, you have to give it a name, username, and password, then you'll see them in the page,
$user="";<---- User name you entered when making the database(prefixed with "a8314628_"),
$password="";<---- password you entered when making the database,
$database="a8314628_forum";<---- looks like you've got this part right,
$hostname="";<---- it will be shown where i mentioned above.,
click the MySql button, ALL the info is right there, if you've set up the db.

here's an example only:
$user="a8314628_something";
$password="password";
$database="a8314628_forum";
$hostname="mysql2.000webhost.com"
忘记你的00wh信息,当你创建数据库时,你必须给它一个名称、用户名和密码,然后你会在页面上看到它们,

$user=”“ 我尝试了下面的代码,它给我的错误如下

无法连接到MySQL:无法访问网络

000webhost只允许您通过自己的PHP主机访问数据库

forget your 00wh info, when you create your database, you have to give it a name, username, and password, then you'll see them in the page,
$user="";<---- User name you entered when making the database(prefixed with "a8314628_"),
$password="";<---- password you entered when making the database,
$database="a8314628_forum";<---- looks like you've got this part right,
$hostname="";<---- it will be shown where i mentioned above.,
click the MySql button, ALL the info is right there, if you've set up the db.

here's an example only:
$user="a8314628_something";
$password="password";
$database="a8314628_forum";
$hostname="mysql2.000webhost.com"
除非您(通过付费)升级您的帐户,否则您无法从自己的计算机访问它。


我尝试了下面的代码,它给出了如下错误

无法连接到MySQL:无法访问网络

000webhost只允许您通过自己的PHP主机访问数据库

forget your 00wh info, when you create your database, you have to give it a name, username, and password, then you'll see them in the page,
$user="";<---- User name you entered when making the database(prefixed with "a8314628_"),
$password="";<---- password you entered when making the database,
$database="a8314628_forum";<---- looks like you've got this part right,
$hostname="";<---- it will be shown where i mentioned above.,
click the MySql button, ALL the info is right there, if you've set up the db.

here's an example only:
$user="a8314628_something";
$password="password";
$database="a8314628_forum";
$hostname="mysql2.000webhost.com"
除非您(通过付费)升级您的帐户,否则您无法从自己的计算机访问它。




将主机命名为“databases.000webhost.com”。如果不进行任何错误检查或处理,则盲目相信连接会工作并使用句柄。连接调用返回
false
(一个布尔值…)如果失败,这就是您发出警告的原因…@Naincy Warning:mysqli_connect():(HY000/2002):第6行/storage/h5/165/847165/public_html/db.php中的连接被拒绝通知:未定义索引:第8行/storage/h5/165/847165/public_html/db.php中的名称通知:未定义索引:第9行/storage/h5/165/847165/public_html/db.php中的地址警告:mysqli_query()预期参数1为mysqli,第12行/storage/h5/165/847165/public_html/db.php中给出的布尔值失败警告:mysqli_close()预期参数1为mysqli,在线/storage/h5/165/847165/public_html/db.php中给出的布尔值18@Naincy对不起,我仍然面对你error@ArunMohan请参阅我的回答“databases.000webhost.com”主机。如果您不进行任何错误检查或处理,您盲目相信连接会工作并使用句柄。连接调用返回
false
(一个布尔值…)如果失败,这就是您发出警告的原因…@Naincy Warning:mysqli_connect():(HY000/2002):第6行/storage/h5/165/847165/public_html/db.php中的连接被拒绝通知:未定义索引:第8行/storage/h5/165/847165/public_html/db.php中的名称通知:未定义索引:第9行/storage/h5/165/847165/public_html/db.php中的地址警告:mysqli_query()预期参数1为mysqli,第12行/storage/h5/165/847165/public_html/db.php中给出的布尔值失败警告:mysqli_close()期望参数1为mysqli,第12行/storage/h5/165/847165/public_html/db.php中给出的布尔值18@Naincy对不起,我仍然面对你error@ArunMohan请看我的答案,明白了吗?如何获取您的00webhost主机名??您好,先生,我不知道您如何获取主机名您的主机名数据库。000webhost.com/localhost是错误的。请从您的主机服务器000webhost获取,您可以通过thia链接了解更多信息。。我找不到mysql.000之类的东西,Hi@ArunMohan我想现在你需要研究如何从Android调用PostAPI,请在本教程中查看:。。。。。。。。。。。Kaushik solanki给出的答案很好…你应该接受我认为的答案…要获得更多android帮助,你可以问android问题。嘿,明白了吗?如何获取您的00webhost主机名??您好,先生,我不知道您如何获取主机名您的主机名数据库。000webhost.com/localhost是错误的。请从您的主机服务器000webhost获取,您可以通过thia链接了解更多信息。。我找不到mysql.000之类的东西,Hi@ArunMohan我想现在你需要研究如何从Android调用PostAPI,请在本教程中查看:。。。。。。。。。。。Kaushik solanki给出的答案很好…你应该接受我认为的答案…要获得更多的android帮助,你可以问android问题。抱歉,仍然错误你的错误是否减少了@ArunMohanya现在减少了,那么错误是什么呢now@ArunMohan我是第一个回答这个问题的人。不管怎样,谢谢你的错误还是没有减少@ArunMohanya现在减少了,那么错误是什么呢now@ArunMohan我是第一个回答这个问题的人。任何可能的解决方案可能的解决方案