Jump to content

Recommended Posts

I am getting the following error:

 

PHP Warning: mysqli_error() expects exactly 1 parameter, 0 given in

 

the error is line 97, which is  $query = "insert into customers(name,address,city,state,zip,country) just updated to 5.2.5, everything was working perfectly before.

 

function insert_order($order_details)
{
  // extract order_details out as variables
  extract($order_details);

  // set shipping address same as address
  if(!$ship_name&&!$ship_address&&!$ship_city&&!$ship_state&&!$ship_zip&&!$ship_country)
  {
    $ship_name = $name;
    $ship_address = $address;
    $ship_city = $city;
    $ship_state = $state;
    $ship_zip = $zip;
    $ship_country = $country;
  }

  $conn = db_connect();

  // insert customer address
  $query = "select customerid from customers where  
            name = '$name' and address = '$address' 
            and city = '$city' and state = '$state' 
            and zip = '$zip' and country = '$country'";
  $result = $conn->query($query)or die(mysqli_error());
  if($result->num_rows>0)
  {
    $customer = $result->fetch_object();
    $customerid = $customer->customerid;
  }
  else
  {
    $query = "insert into customers(name,address,city,state,zip,country) values($name','$address','$city','$state','$zip','$country')";
$result = $conn->query($query)or die(mysqli_error());
    if (!$result)
       return false;
  }
  $customerid = $conn->insert_id;

  $date = date('Y-m-d');
  $query = "insert into orders values
            ('', $customerid, ".$_SESSION['total_price'].", '$date', 'PARTIAL', '$ship_name',
             '$ship_address','$ship_city','$ship_state','$ship_zip',
              '$ship_country', '0', '0', '0', '0', '0', '0', '0','0','0','0','0','0','0','0')";

  $result = $conn->query($query)or die(mysqli_error());
  if (!$result)
    return false;

  $query = "select orderid from orders where 
               customerid = $customerid and 
               amount > ".$_SESSION['total_price']."-.001 and
               amount < ".$_SESSION['total_price']."+.001 and
               date = '$date' and
               order_status = 'PARTIAL' and
               ship_name = '$ship_name' and
               ship_address = '$ship_address' and
               ship_city = '$ship_city' and
               ship_state = '$ship_state' and
               ship_zip = '$ship_zip' and
               ship_country = '$ship_country'";
  $result = $conn->query($query);
  if($result->num_rows>0)
  {
    $order = $result->fetch_object();
    $orderid = $order->orderid;
  }
  else
    return false;

Link to comment
https://forums.phpfreaks.com/topic/92040-525-error/
Share on other sites

$query = "insert into customers(name,address,city,state,zip,country) values($name','$address','$city','$state','$zip','$country')";
$result = $conn->query($query)or die(mysqli_error());

I think the bottom line above is what it is actually complaining about. First the $query is invalid because of

($name','$address'

--notice the first single quote, invalid because it doesn't have a starting quote

 

because of the invalid $query, the $conn->query($query) will fail with an error and the die() will execute.  It doesn't like the mysqli_error() having no parameter.  It wants the link identifer

http://us.php.net/manual/en/function.mysqli-error.php

 

I don't think you can get away with putting the $conn in there because it  is the whole object but it only wants the link identifier.

 

the reason the problem never happened before is because you never had a query error before and the

die(mysqli_error());

never tried to execute before

Link to comment
https://forums.phpfreaks.com/topic/92040-525-error/#findComment-471393
Share on other sites

here is the original code that was working before the server change. I can't figure out what's wrong here.

 

function insert_order($order_details)
{
  // extract order_details out as variables
  extract($order_details);

  // set shipping address same as address
  if(!$ship_name&&!$ship_address&&!$ship_city&&!$ship_state&&!$ship_zip&&!$ship_country)
  {
    $ship_name = $name;
    $ship_address = $address;
    $ship_city = $city;
    $ship_state = $state;
    $ship_zip = $zip;
    $ship_country = $country;
  }

  $conn = db_connect();

  // insert customer address
  $query = "select customerid from customers where  
            name = '$name' and address = '$address' 
            and city = '$city' and state = '$state' 
            and zip = '$zip' and country = '$country'";
  $result = $conn->query($query);
  if($result->num_rows>0)
  {
    $customer = $result->fetch_object();
    $customerid = $customer->customerid;
  }
  else
  {
    $query = "insert into customers values
            ('', '$name','$address','$city','$state','$zip','$country')";
    $result = $conn->query($query);
    if (!$result)
       return false;
  }
  $customerid = $conn->insert_id;

  $date = date('Y-m-d');
  $query = "insert into orders values
            ('', $customerid, ".$_SESSION['total_price'].", '$date', 'PARTIAL', '$ship_name',
             '$ship_address','$ship_city','$ship_state','$ship_zip',
              '$ship_country', '0', '0', '0', '0', '0', '0', '0','0','0','0','0','0','0','0')";

  $result = $conn->query($query);
  if (!$result)
    return false;

  $query = "select orderid from orders where 
               customerid = $customerid and 
               amount > ".$_SESSION['total_price']."-.001 and
               amount < ".$_SESSION['total_price']."+.001 and
               date = '$date' and
               order_status = 'PARTIAL' and
               ship_name = '$ship_name' and
               ship_address = '$ship_address' and
               ship_city = '$ship_city' and
               ship_state = '$ship_state' and
               ship_zip = '$ship_zip' and
               ship_country = '$ship_country'";
  $result = $conn->query($query);
  if($result->num_rows>0)
  {
    $order = $result->fetch_object();
    $orderid = $order->orderid;
  }
  else
    return false; 

Link to comment
https://forums.phpfreaks.com/topic/92040-525-error/#findComment-471677
Share on other sites

The change is to do with the mysqli extensions your are using not your code. You are getting confused with mysql_error function from the standard mysql extension. which can accept an optional link resource parameter. With the release of the mysqli extension the mysqli_error function now requires the link resource.

 

Try passing the $conn variable as the parameter when calling mysqli_error.

$query = "insert into customers(name,address,city,state,zip,country) values($name','$address','$city','$state','$zip','$country')";

$result = $conn->query($query)or die(mysqli_error($conn));

Link to comment
https://forums.phpfreaks.com/topic/92040-525-error/#findComment-472005
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.