Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

php - Stuck at this error: Incorrect integer value: '' for column '____' at row 1

When I submit the form and use this script to insert the data in the db i get the error mentioned above...any ideas?

        //Include connect file to make a connection to test_cars database
        include("prototypeconnect.php");


        $proCode            =       $_POST["code"];
        $proDescr           =       $_POST["description"];
        $proManu            =       $_POST["manufacturer"];
        $proCPU             =       $_POST["cost_per_unit"];
        $proWPU             =       $_POST["weight_per_unit"];
        $proBarCode         =       $_POST["bar_code"];
        $proIngredients     =       $_POST["ingredients_list"];
        $proAllergens       =       $_POST["allergens_contains"];
        $proMayAllergens    =       $_POST["allergens_may_contain"];

        //Insert users data in database
        $sql = "INSERT INTO prodb.simplex_list 
                   code, description, manufacturer, 
                   cost_per_unit, weight_per_unit, bar_code,
                   ingredients_list, allergens_contains,
                   allergens_may_contain) 
                VALUES 
                  ( '$proCode', '$proDescr' , '$proManu', 
                   '$proCPU' , '$proWPU' , '$proBarCode', 
                   '$proIngredients' , '$proAllergens', 
                   '$proMayAllergens')";

        //Run the insert query

        if (!mysql_query($sql)) {
            echo mysql_error();
        }

    ?>

UPDATE: I removed id inserts as they are auto-increment and i learned from your answers that a null does not need to be coded and mysql looks after AI. Thanks guys!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Query need to be like:-

 $sql = "INSERT INTO prodb.simplex_list 
         (code, description, manufacturer, 
          cost_per_unit, weight_per_unit, 
          bar_code, ingredients_list, allergens_contains, 
          allergens_may_contain) 
         VALUES ('$proCode', '$proDescr', '$proManu',
                 '$proCPU','$proWPU', '$proBarCode', 
                 '$proIngredients', '$proAllergens', 
                 '$proMayAllergens')";

Note:- please stop using mysql_*. Use mysqli_* or PDO. Also this will work only when id field must be auto incremented.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...