How do I retrieve "textarea" value from php

Right now this is my html code one more this is that this div col-6 is inside form tag

<div class="col-6">
                  <div class="form-group">
                    <label for="Description" class=" form-control-label">Description</label>
                      <textarea name="descrp"  id="descrip" cols="50" rows="10" spellcheck="true">
                          
                        </textarea>

                  </div>
              </div>

is it a form using method=post, or method=get?

Post method but It did not get using $_POST['descrp']

Well, that’s how you would get the value of it.

Can you show us the full form HTML?

sure! wait

If you’re not getting what you expect you can always try var_dump($_POST) to see what’s in the post array.


<div class="content">
    <div class="col-lg-8">
        <div class="card">
            <div class="card-header"><strong>Add New</strong><small> Task</small></div>
            <div class="card-body card-block">
                <form action="../includes/addNewTask.inc.php" method="post" class="col-form-legend"> 
                <div class="form-group">
                    <label for="task-title" class=" form-control-label">Task Title</label>
                    <input type="text" name="task-title" id="company" autofocus = "true" placeholder="Enter your Task Title" class="form-control">
                </div>
                              
                    <div class="form-group">
                            <label for="">Assign To </label>
                              <select name="assign-to[]" data-placeholder="Select an Employees...." multiple class="standardSelect">
                               <?php if ($resultCheck > 0): ?>
                                <?php while ($row = mysqli_fetch_assoc($result)): ?>
                                <option value="<?php echo $row['emp_id'] ?>"><?php echo $row['fname'].' '.$row['lname']; ?></option>
                            <?php endwhile; ?>
                        <?php endif; ?>
                            </select>

                </div>
           
                <div class="form-group">
                    <label for="start-date" class=" form-control-label">Start Date</label>
                    <input type="date" name="start-date" id="start-date" class="form-control">
                </div>
                 <div class="form-group">
                    <label for="due-date" class=" form-control-label">Due Date</label>
                    <input type="date" name="due-date" id="due-date" placeholder="" class="form-control">
                </div>

                

                <!--                     
                <div class="col-6">
                <div class="form-group">
                    <label for="status" class=" form-control-label">Status</label>
                          <select   name="status" class="form-control standardSelect" tabindex="1">
                            <option value="pending">Pending</option>
                            <option value="started">Started</option>
                            <option value="completed">Completed</option>                            
                        </select>
               </div>   
             </div> -->
              <div class="col-6">
                  <div class="form-group">
                    <label for="Description" class=" form-control-label">Description</label>
                      <textarea name="descrp"  id="descrip" cols="50" rows="10" spellcheck="true">
                          
                        </textarea>

                  </div>
              </div>

                <div class="card-footer">
                    <button name="task-submit" type="submit" class="btn btn-info float-right">
                     Add</button>
                </form>
                 </div>  
       </div>
    </div>

                    
</div>
</div>

And this is image of that form

ohh yes Thanks @Gandalf let me check

The form pasted does not contain your textarea.

Plus:

noooope. try again.

1 Like

The image you’ve posted and the code are not the same form. The code is asking for first and last name and there’s no description.

1 Like

Sorry @m_hutley it’s my mistake I update the correct code now you can see
I give that form an action and method as well POST

With the code as amended, $_POST[‘descrp’] should be set.

As gandalf said, var_dump($_POST) at the top of addNewTask.inc.php and see what’s in the array.

ok let me check :+1:

dear friend I am getting an error undefined Index: descrp;
could you please look my code and tell why its giving me an error!

<?php 
   
   	$descript = $_POST['decrp'];
   	echo var_dump($descript);
   		
   
require_once 'db.inc.php';
if (isset($_POST['tas-submit'])) {
   $task_title = $_POST['task-title'];
   $assignTo = $_POST['assign-to[]'];
   $startDate =strtotime($_POST['start-date']);
   $dueDate = strtotime($_POST['due-date']);
   $status = $_POST['status'];
   $descript = $_POST['decrp'];
   

   if (empty($task_title || $assign_to || $start_date || $due_date)){
   	header("Location: ../admin/add-new-task.php?error=emptyfields&start_date".$startDate."&end_date=".$dueDate."&assignto=".$assignTo."&task_title".$task_title, true);
   	exit();
   }
   else if (!preg_match("/^[a-zA-Z0-9]*$/", $task_title)) {
   	header("Location: ../admin/add-new-task.php?error=invalid-Title", true);
   	exit();
   }
   elseif (!empty($assignTo)) {
   		foreach ($assignTo as $empId) {
   			echo "</br>";
   			echo "$empId";
   			
   		}
   }
   

   else {
   	$sql = "INSERT INTO sys_task(task,start_date,due_date,status) VALUES (?, ?, ?, ?)";
   	$stmt = mysqli_stmt_init($conn);
   		if (!mysqli_stmt_prepare($stmt, $sql,)) {
   			header("Location: ../admin/add-new-task.php?error=sqlError", true);
   			exit();
   		}
   		else {
   		mysqli_stmt_bind_param($stmt, 'siis',$task_title,$startDate,$dueDate,$status);
   		mysqli_stmt_execute($stmt);
   		mysqli_stmt_store_result($stmt);

   		header("Location: ../admin/add-new-task.php?result=Task_is_successfully_added&description={$descript}&start_date=".$startDate."&end_date=".$dueDate."&assignto=".$emp_id."&task_title".$task_title."&status=".$status, true);
   		exit();
   		}



   }
   mysqli_stmt_close($stmt);
   mysqli_close($conn);






}

look closer at that array index…something missing?

2 Likes

Hey @m_hutley alright Thank you so much! :smiley::+1:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.