خرید بک لینک

Vote count: 0

I have a form which has multiple drop downs (16) speed[] and some other fields

The data from the dropdown boxes has to be inserted into a Mysql table

What I did is I took the count count($_POST["speed"]);and then loop through until the end of the speed array.

The problem is:

  1. If Anyone of the dropdown is not selected it retus "-1", if used `($_POST["speed"][$i]!="-1")for that but it does not compare and goes into the IF loop

  2. The Insert Query is not a valid not sure how to append the extra commas

$sql when printed

INSERT INTO mytablename (w_name,wtype,speed1,speed2, speed3, speed4, speed5, speed6, speed7, speed8, speed9, speed10, speed11, speed12, speed13, speed14, speed15, speed16, coach_id) VALUES ('name', '', ''-1''800''-1''-1''200''-1''-1''-1''-1''-1''-1''-1''-1''-1''-1''200'', '208')

My PHP code

 $itemCount = count($_POST["speed"]);
        $itemValues=0;
        $query = "INSERT INTO mytablename (workout_name,w_name,speed1,speed2, speed3, speed4, speed5, speed6, speed7, speed8, speed9, speed10, speed11, speed12, speed13, speed14, speed15, speed16, coach_id) VALUES ";
        $bldSpltString="";
        $queryValue = "";
        for($i=0;$i<$itemCount;$i++) {
            if(($_POST["speed"][$i]!="-1") || !empty($_POST["speed"][$i])) {

                $bldSpltString .= "'" .  $_POST["speed"][$i] ."'";
            }
        }
        $queryValue .= "('" . $workout . "', '" . $wtype . "', '" . $bldSpltString . "', '" .$_SESSION['id']."')";

        $sql = $query.$queryValue;
        echo $sql;
        exit;

asked 23 secs ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 29 خرداد 1395 ساعت: 4:49

صفحه بندی