Question

( ! ) Notice: Undefined index: temps in C:\wamp\www\testlp\insert.php on line 165

Hello this is the error I get when I try to post

if  (isset($_POST['numpro']) )
        {
            $post_count = count($_POST['numpro']);
            for ($i=0;$i<$post_count;$i++) 
            {

                if ($_POST['numpro'][$i] !="")
                {
                    $numpro = mysql_real_escape_string($_POST['numpro'][$i]);
                    $prodesc = mysql_real_escape_string($_POST['prodesc'][$i]);
                    $tache = mysql_real_escape_string($_POST['tache'][$i]);
                    $prolieu  = mysql_real_escape_string($_POST['prolieu'][$i]);
                    $tempsmo = ($_POST['temps'][$i]);

                    print_r($_POST);
                    $query = mysql_query("INSERT INTO projetstaches (prtDescription,prtLocation,prtTaskId,prtProjetNum,prtDate,prtTimeSheetId, prtTime) VALUES 
                    ( '$prodesc' ,'$prolieu', '$tache'  ,'$numpro','$date1'  ,'$timId',  '$tempsmo'  )", $connection );   

                } 
            }
        }   

This is how I made my temp ( this is javascript cause this is a append button)

$('#calculTempsdiv').append(
                $(   '<input id="temps' + counter + '" name="temps' + counter + '" type="number" size="10" min="0" max="24" value="0" step="any" onchange="checkField();" class="dynamic" onblur="autre();" onfocus="enter();"/>')  
                )   

How Do I solve this problem?

Was it helpful?

Solution

You are submitting a form with elements like temps1, temps2 etc. Accessing them is therefore done with $_POST['temps1'] and similar.

Instead, try name="temps[]". This will give you the array $_POST['temps'][] you appear to be expecting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top