Martinovska
Martinovska

Reputation: 89

{php} Column count doesn't match value count at row 1

I make a add forum

if ($_SERVER['REQUEST_METHOD'] == "POST" AND isset ($_REQUEST['addfinal'])) {

    $name_1 = clear_form_text ($_REQUEST['name_1']);
    $name_2 = clear_form_text ($_REQUEST['name_2']);
    $car_name = intval ($_REQUEST['id_car_name']);


    if (empty ($name_1)) $stop .= "Error text!<br>";
    if (empty ($name_2)) $stop .= "Error text!<br>";

    if ($stop == false) {

        $db->query ("INSERT INTO car_class (name_1, name_2, id_car_name) VALUES ('$name_1', '$name_2' '$car_name')") or die ($db->error);
        $infomessage = "<div class=\"attention-box attention-success\"><p class=\"text-muted\">Add success. <a href=\"index.php?module=school_class\">Back</a></p></div>";

    } else {

        $infomessage = "<div class=\"attention-box attention-danger\"><p class=\"text-muted\">" . $stop . " <a href=\"javascript:history.back();\">Врати се назад</a></p></div>";

    }

} else {

    $result = $db->query("SELECT id, name FROM car_name");
       while ($row = $result ->fetch_array())
        $arrayrow[] = $row; 

        foreach ($arrayrow as $row) {
            $select .= "<option value='".$row['id']."'>".$row['name']."</option>";

        }

    $template->set_block ('car_class-add', '', 'car_class');
    $template->set ('car_name', $select, 'car_class');

}

The Select need to read values from car_name (id, name) and writes it id in car_class

But when i click on submit give me Column count doesn't match value count at row 1

Where is the problem with this code?

Thank you

EDIT Problem from above is solved. NOW script work but do not write value in id_car_name Only write 0 car_class.id_car_na‌​me = car_name.id Why still this problem?

Upvotes: 0

Views: 51

Answers (1)

Imanez
Imanez

Reputation: 514

You must add comma after '$name_2' :

 $db->query ("INSERT INTO car_class 
                     (name_1, name_2, id_car_name) 
              VALUES ('$name_1', '$name_2', '$car_name')") 
        or die ($db->error);

Upvotes: 2

Related Questions