1

The error occurs on line 22

$insert->bind_param('sss', $make, $model, $desc);

and that's rest of the code:

<?php
error_reporting(E_ALL); ini_set('display_errors', 'On');
require 'connect.php';
require 'function/security.php';

//creating empty array
$records = array();

//check if data is available
if(!empty($_POST)) {
    if(isset($_POST['make'], $_POST['model'], $_POST['desc'])) {

    $make =  trim($_POST['make']);
    $model = trim($_POST['model']);
    $desc =  trim($_POST['desc']);  

    //check if thay empty
    if(!empty($make) && !empty($model) && !empty($desc)) {
    //prepering statement
    $insert = $db->prepare("INSERT INTO type ('make', 'model', 'desc') VALUES(?, ?, ?)");
    ///sss represents 3 strings
    $insert->bind_param('sss', $make, $model, $desc);

    //executing prepared statement
    if($insert->execute()) {
        header('Location: form.php');
        die();
    }
    }
    }
    }


//creating if statement and assigning results variable
if($results = $db->query("SELECT * FROM type")) {
    if($results->num_rows) {
        while($row = $results->fetch_object()) {
            $records[] = $row;
        }
        $results->free();
    }
}

?>

Just can't figure it out what's wrong with it, went thru hundreds of tutorials and read all post with same topic in stackoverflow and still can't find the error. Please help

Thanks for all your help, I sorted it out... only 10 hours took me to realize my table is called desc and its Mysql reserved word!

elizunia2
  • 9
  • 2
  • What, exactly, is the error? – Celeo Dec 12 '14 at 21:45
  • Don't put your field names in single quotes. – gen_Eric Dec 12 '14 at 21:45
  • 3
    Field names go in backticks, not single quotes. – Niet the Dark Absol Dec 12 '14 at 21:45
  • P.S. After doing `$db->prepare()`, you should do `if($insert === FALSE){ die($db->error); }` – gen_Eric Dec 12 '14 at 21:46
  • If you'd bothered checking if your prepare statement had actually succeeded, you wouldn't have needed to ask this particular question. – Marc B Dec 12 '14 at 21:46
  • you should use 'or die("Error: "$mysqli->error());' more often.. it helps in debugging, add it after any database management calls. in your case it's: '''$insert = $db->prepare("INSERT INTO type ('make', 'model', 'desc') VALUES(?, ?, ?)") or die ("Insert error: " $db->error();''' – bakriawad Dec 12 '14 at 21:51

0 Answers0