PHP.ini causes Warning: mysqli_error() expects par

2020-05-10 06:36发布

this script works fine on Local Host and Other free Hosting but not on "host Gator "it should be " PHP.ini " Any Help !?!?

function.php

<?php
    date_default_timezone_set("America/Chicago");
    echo date("Y/m/d H:i:s");
function consql($con){
    $con=mysqli_connect("host","BDusername","DBPassWord","DB") or die( mysqli_error($con));}
?>

index.php

line #1 "Very top "

<?php
SESSION_START();
require_once"inc/function.php";
consql($con);
?>

line#12

  <?php
    if(isset($_SESSION['user']))
    {
        header("location:users.php");
    }
    elseif(isset($_POST['submit']))
    {
        $result=mysqli_query("select user_id,password from user_login where name='$_POST[username]'")     or die(mysqli_error($con)); // ** line # 19 ** //
        $n=mysqli_fetch_assoc($result);
        if($n['password']!=$_POST['userpassword'])
        {
          echo "user name or password wrong";
        }
        else
        {
          echo "you loged in as $_POST[username]";
          $_SESSION['user']=$n['user_id'];
          header("location:users.php");
        }
    }
    else 

I'm new to mysqli and looked up here for same error but didn't get the point on most of them.

标签: php mysqli
2条回答
手持菜刀,她持情操
2楼-- · 2020-05-10 06:46

U can use

function consql(&$con){
  $con=mysqli_connect("host","BDusername","DBPassWord","DB") or die( mysqli_error($con));
}

so this is call by refrence and $con can use at any page once U call the function

or use global $con; before the connection line

查看更多
我只想做你的唯一
3楼-- · 2020-05-10 07:06

function.php

function consql()
{
    $con=mysqli_connect("host","BDusername","DBPassWord","DB") or die( mysqli_error($con));
    return $con;
}

index.php

require_once"inc/function.php";
$con = consql();

explanation : why no error appears in your localhost‌? is it a PHP.ini problem ?

maybe errors are hidden on your localhost or mysqli_query runs with no problem there. but there is a problem on your host, such as connection problem, missing or broken database table or etc... base on your code, when no error occurs, mysqli_error() wont run and you dont get error

查看更多
登录 后发表回答