mysqli_prepare() expects parameter 1 to be mysqli

前端 未结 3 1137
一个人的身影
一个人的身影 2021-01-28 05:15

Having trouble with procedural use of mysqli

Here\'s the function:

db.php



        
相关标签:
3条回答
  • 2021-01-28 06:08

    Since $link is being define in db.php probably you should

    require db.php;
    

    in function.php file

    0 讨论(0)
  • 2021-01-28 06:13
    `enter code here`
    need
       <?php
    function addItemToCatalog($var1, $var2, $var3, $var4) {
        $sql = 'INSERT INTO catalog (var1, var2, var3, var4, $link) 
                VALUES (?, ?, ?, ?)';
    
    end
    <?php
    require_once ("db.php");
    require_once ("function.php");
    
    $var1 = $_POST['var1']; //showing without filtering methods
    $var2 = $_POST['var2'];
    $var3 = $_POST['var3'];
    $var4 = $_POST['var4'];
    
    if(!addItemToCatalog($var1, $var2, $var3, $var4, $link)){ 
        echo 'some error text';
    
    0 讨论(0)
  • 2021-01-28 06:14

    The way the two files db.php and function.php are glued together I think results in $link being defined as a global variable - you need to use global to access it within function:

    function addItemToCatalog($var1, $var2, $var3, $var4) {
        global $link;
        ...
    }
    

    or give the $link to the function explicitly through parameter:

    function addItemToCatalog($var1, $var2, $var3, $var4, $link) {
        ...
    }
    
    0 讨论(0)
提交回复
热议问题