Question

Undefined variable: timComment . Hello this is the error I have when I'm trying to get my variable before send into my database. I have 3 sheet. MY first one is timesheet.php ( where my textarea with the id timComment is made) . My timesheet include autocomplete.php where I have most of all my code,input, fonction and where the button finish is here. When I press finish button it's going to insert.php where I have my sql syntax.

here is my timesheet where I made the textarea

<div class="header">
        Commentaires spéciaux : 
        </br>
        <textarea rows="4" cols="88" id="timComments"> </textarea>
        </br>
        </br>
    </div>

Here where I have my button in autocomplete.php

<input type="submit" name="submit_val"  value="Terminé" id="end" />
<input type="hidden" name="data" value="<?php echo $date; ?>" />
<input type="hidden" name="usrUserName" value="<?php echo $usrUserName; ?>" />
<input type="hidden" name="timComments" value="<?php echo $timComments; ?>" />

And here where I trying to get my textarea to send in the database (insert.php)

$timComments =  $_POST['timComments'] ;
echo($timComments); 

( I know how to insert in database but if it's echo my timcomments correctly I'm able to continue.

EDIT

here my sql

// Insertion timesheet le timUserdID, creation de la date, date de la semaine
    $req = $bdd->prepare('INSERT INTO timesheets (timUserID,timCreatedDate, timDateStartOfWeek,timComments) VALUES(:usrUserName, CURDATE(),:timDateStartOfWeek,:timComments) ');
    $req->execute(array('usrUserName' => $usrUserName,'timDateStartOfWeek' => $timDateStartOfWeek,'timComments' => $timComments,));

Here is the link of my total code insert.php and timesheet.php

http://pastebin.com/pQKGWjzF

Was it helpful?

Solution

The reason you are getting the undefined index error, is because POST variables need to contain name="xxx". You only give it an id whereas you need to name it.

<textarea rows="4" cols="88" id="timComments" name="timComments"> </textarea>
//                                            ^^^^^^^^^^^^^^^^^^

OTHER TIPS

Should be like this, you forget to give 'name' property:

<textarea rows="4" cols="88" id="timComments" name="timComments"> </textarea>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top