-3

I am trying to insert a data to a table but I am getting this frustrating error that I couldn't figure what is wrong. The error is as below:

Fatal error: Call to a member function bind_param() on a non-object

I have read it means prepare is returning false.. Here is the code where the error is occuring

$insert = $mysqli->prepare("insert into `hm_desktop`(`username`, `title`, `condition`, `description`, `price`, `brand`, `color`, `hard_drive_capacity`, `others`, `graphics_card`, `ram_capacity`, `operating_system`, `os_edition,` `processor_type`, `processor_speed`, `model`, `product_series`, `included_items`,  `country`, image_one, image_two, image_three, image_four, image_five, `date`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$insert->bind_param('sssssssssssssssssssss', $username, $title, $cond, $desc, $price, $brand, $color, $hard_drive_type, $others, $garphics_card, $ram_capacity, $operating_system, $os_edition, $processor_type, $processor_speed,$model, $product_series, $included_items,  $country, $random_name_generated, $i2, $i3, $i4, $i5, $date);
$insert->execute();

I have tried everything I could for hours but nothing seems to be working.. What am I missing here? please help

Bart Friederichs
  • 32,037
  • 14
  • 96
  • 185
hmaxx
  • 523
  • 2
  • 7
  • 16
  • 1
    `$mysqli->prepare` returns `false` when there is an error. False is a "non-object". Read the [manual](http://php.net/manual/en/mysqli.prepare.php) – UnholyRanger Jul 31 '13 at 14:08
  • Check `$mysqli->error`. – Bart Friederichs Jul 31 '13 at 14:08
  • @BartFriederichs where should I put `$mysqli->error`? – hmaxx Jul 31 '13 at 14:11
  • `echo` it, tell us what it say and we might be able to help you. – Bart Friederichs Jul 31 '13 at 14:12
  • @BartFriederichs `You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`processor_type`, `processor_speed`, `model`, `product_series`, `included_items`' at line` – hmaxx Jul 31 '13 at 14:16
  • See answer to similar question at http://stackoverflow.com/questions/27394710/fatal-error-call-to-a-member-function-bind-param-on-boolean/27394772#27394772 – RobP Dec 13 '16 at 14:54

2 Answers2

0

I see two issues:

You have 21 s's and 25 variables.

You've misspelled graphics_card (unless it's spelled the same way when you declared it)

Use this line instead:

$insert->bind_param('sssssssssssssssssssssssss', $username, $title, $cond, $desc, $price, $brand, $color, $hard_drive_type, $others, $graphics_card, $ram_capacity, $operating_system, $os_edition, $processor_type, $processor_speed,$model, $product_series, $included_items,  $country, $random_name_generated, $i2, $i3, $i4, $i5, $date);

Also, os_edition has the tick on the wrong side of the comma.

aynber
  • 20,647
  • 8
  • 49
  • 57
0

You have a mistake in your SQL.

The comma after os_edition is inside the backticks, it should be outside:

....ating_system`, `os_edition,` `processor...

....ating_system`, `os_edition`, `processor...

That, and what @aynber said about the s's, variables and the graphics_card.

Bart Friederichs
  • 32,037
  • 14
  • 96
  • 185