0

I need a little help again... I get error mysql parameters, I know the problem but I cant find the missing parameters... this is the problem line

**`$result_template = mysqli_query($select_template) or die(mysql_error());`**

I know 1 parameter is missing but I dont know whichone?? Can you pls help me? Thanks

This is part of the codes maybe usefull....

/*function to display the active template*/


    function displayTemplate(){
        $tableprefix = "";
        global $tableprefix,$_SESSION;
        $template_array = array();

         $select_template = "SELECT vtop_filename,vleft_filename,vbottom_filename,vimages_folder,vcss_name,vtemplate_name
                            FROM ".$tableprefix."template_master WHERE vactive_status = 'Y'";

1579---->>>>   $result_template = mysqli_query($select_template) or die(mysql_error());

        $template_row = mysql_fetch_assoc($result_template);

        array_push($template_array,$template_row['vtop_filename'],$template_row['vleft_filename'],$template_row['vbottom_filename'],$template_row['vimages_folder'],$template_row['vcss_name'],$template_row['vtemplate_name']);

    return $template_array; 
    }
Mehul Kuriya
  • 608
  • 5
  • 18
Murat
  • 41
  • 4
  • You beed ti pass the connection variable to the mysqli function – Kinshuk Lahiri Oct 08 '16 at 05:50
  • 1
    Sorry @Kinshuk I cant understand – Murat Oct 08 '16 at 05:53
  • you missed to the Connection object....Here is quick syntax ref `$res=mysqli_query($con_object,$query);` – RohitS Oct 08 '16 at 05:54
  • 1
    `mysqli_query($conn,$select_template) ` ADD YOUR CONNECTION VARIABLE – Karthi Oct 08 '16 at 05:55
  • 1
    You have set the mysqli_connect in some variable. Pass that variable to the function at the first position. – Kinshuk Lahiri Oct 08 '16 at 05:57
  • Notice: Undefined variable: con_object in D:\wamp64\www\magento\includes\functions.php on line 1579 – Murat Oct 08 '16 at 05:59
  • also undefined variable $conn either – Murat Oct 08 '16 at 05:59
  • @Murat you took it in wrong sense...i meant the connection object that you have initialize something like `$con=mysqli_connect('servername/ip','username','password','databasename'); `then use `$res=mysqli_query($con,$query);` also these are syntax only you have to modify according to your need... – RohitS Oct 08 '16 at 06:05
  • `mysql_fetch_assoc` != `mysqli_*`. Nor does `mysql_error()`. – chris85 Oct 08 '16 at 06:11
  • Im really confuse I think... I cant fix this... try every think who says somethink here... but always got same message "undefined variable:" ! :( – Murat Oct 08 '16 at 06:31
  • I change the problem line like this $result_template = mysqli_query($select_template, $tableprefix) or die(mysqli_connect_error()); and finally avoid "undefined variable" error... but now I have new error... Warning: mysqli_query() expects parameter 1 to be mysqli, string given in D:\wamp64\www\magento\includes\functions.php on line 1592 :( – Murat Oct 08 '16 at 06:41
  • Look at the manual. Parameter 1 connection, parameter 2 query. – chris85 Oct 08 '16 at 14:54

2 Answers2

1

You need to tell it where to connect to. Here is a simple example of working code to connect to a database from PHP.

 <php 

//Connect to DB 
$conn = new mysqli("Hostname","Username","Password","Database"); 

//If the connection has errors 
if ($conn->connect_error){ 
  //Display the error 
  die("Connection failed because: " . $conn->connect_error); 
} 

//Otherwise the connection is good so lets create a sql query 
$sql = "SELECT * FROM Database"; 

//Get the results of the query 
$result = $conn->query($sql); 
Peavey2787
  • 128
  • 1
  • 10
1

You should refer the php documentation for this here

As you are using the procedural style, so you will have to pass the mysqli_connect resource to your mysqli_query

<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* Create table doesn't return a resultset */
if (mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
    printf("Table myCity successfully created.\n");
}

/* Select queries return a resultset */
if ($result = mysqli_query($link, "SELECT Name FROM City LIMIT 10")) {
    printf("Select returned %d rows.\n", mysqli_num_rows($result));

    /* free result set */
    mysqli_free_result($result);
}

/* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */
if ($result = mysqli_query($link, "SELECT * FROM City", MYSQLI_USE_RESULT)) {

    /* Note, that we can't execute any functions which interact with the
       server until result set was closed. All calls will return an
       'out of sync' error */
    if (!mysqli_query($link, "SET @a:='this will not work'")) {
        printf("Error: %s\n", mysqli_error($link));
    }
    mysqli_free_result($result);
}

mysqli_close($link);
?>

but as I can see that you are using it in some function so pass an object of db to this function and then use it in your mysqli_query

Rohit Ailani
  • 910
  • 1
  • 6
  • 19