0

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?

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

6 Comments

oh yes thank you, now work but do not add id_car_name only write 0. car_class.id_car_name = car_name.id
when you use var_dump(intval ($_REQUEST['id_car_name'])). what do you get ?
after $car_name = intval ($_REQUEST['id_car_name']); add var_dump to check the value
So the problem came form $_REQUEST['id_car_n‌​ame'] , check it (if id_car_n‌​ame is the correct name... )
I change $_REQUEST with $_POST and now work. It's correct this?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.