0

There have been lots of posts about this and crawled them all but can't figure out why im getting this message. I am not good with SQl and this coding so really hope someone can help.

A customer can checkout and order fine but after Sagepay always presented with the above error message. (line 70 in bold below)

$query="SELECT surname, town, county, country, currencyID, goodsTotal, shippingTotal, taxTotal, discountTotal FROM $tableOrdersHeaders WHERE orderID = '$myOrderID' AND randID = '$myRandID' LIMIT 1";

        **$result = mysqli_query($query) or die( "Unable to retrieve order details");**
        $num_results = mysqli_num_rows($result); 

        if ($num_results > 0){
            // build the array from the results
            $ga_order = mysqli_fetch_array($result, MYSQL_ASSOC);
        } else {
            die( "No matching order found");

Now the DB access file for SQLI code I believe it uses is

function connect($sql_host_name,$sql_username,$sql_password,$sql_database_name) {
        $this->currentDatabase = $sql_database_name;
        $this->resID = @mysqli_connect($sql_host_name,$sql_username,$sql_password);
        if ($this->resID == FALSE) {
            $this->lastError = "Could not connect to mySQL server";
            return FALSE;
        } else {
            if (@mysqli_select_db($this->resID, $sql_database_name)) {
                return TRUE;
            } else {
                return @mysqli_query($this->resID,"create database $sql_database_name");
                return FALSE;

Really hope someone can help.

Haymaker
  • 121
  • 13
Robert
  • 1
  • Check your query. That is where the error will be. If you can check the query using an actual MySQL terminal, it will give you more information. – Ramsay Smith Jan 18 '16 at 18:28

1 Answers1

1

If you are using the procedural style of mysqli functions, you mysqli_query needs the connection variable as the first argument, followed by the query string.

It looks like you are just giving it the query string on here: $result = mysqli_query($query) or die( "Unable to retrieve order details");.

You'll want something like: $result = mysqli_query($connection, $query).

Reference: http://php.net/manual/en/mysqli.query.php

kunruh
  • 874
  • 1
  • 8
  • 17
  • Hello I have tried adding $connection to the string before and received same error message? Tried $connect & $connection as suggested on other posts. – Robert Jan 19 '16 at 09:30
  • Without knowing the exact structure of your code provided, I'm not 100% sure what variable is your mysql link, but it _looks_ like it should be `$this->resID`. – kunruh Jan 19 '16 at 20:52