Reputation: 45
As i want to get the form data and want to process that data and store into database..I am getting all checked box values but i am enable to get the text value although i used $_POST['text-name'] in the code...Please help me to get the error..My code is Below
if(isset($_POST['give-score'])&&!empty($_POST['checked'])){
$employeedetails = $_POST['checked'];
$score = $_POST['score'];
$username = $employeedetails[1];
$workname = $employeedetails[2];
changeworkstatus($username,$workname,$con);
$workname = $employeedetails[2];
addscorepoints($workname,$score,$con);
}else{
echo "";
}
and my form html code is below
<td><input type="checkbox" name="checked[]" id="employeework" value="" style="align: center"></td>
<td><input type="checkbox" name="checked[]" id="employeework"value="<?php echo $results['username']; ?>"><?php echo $results['username']; ?></td>
<td><input type="checkbox" name="checked[]" id="employeework"value="<?php echo $results['work_name'];?>"><?php echo $results['work_name'];?></td>
<td><input type="text" name="score" id="score" placeholder="Your Score Here"></td>
<td><input type="submit" name="give-score"></td>
php part used in the table are working fine..but the input[type=text] i am not getting that value..
Upvotes: 0
Views: 829
Reputation: 157
I think there is no problem in your code even then I am providing the following code which I've tried. I am getting all values from the form elements.
Code of the html file
<html>
<body>
<form action="test.php" method="POST"> Checked value:
<td><input type="checkbox" name="checked[]" id="t1" value="test1">test1</td>
<td><input type="checkbox" name="checked[]" id="t2" value="test2">test2</td>
<td><input type="checkbox" name="checked[]" id="t3" value="test3">test3</td>
<td><input type="text" name="score" id="score" placeholder="Your Score Here"> </td>
<td><input type="submit" name="give-score"></td>
</form>
</body>
</html>
Code of PHP file
<?php
if(isset($_POST['give-score'])&&!empty($_POST['checked'])){
$employeedetails = $_POST['checked'];
echo $score = $_POST['score']."<br>";
echo $username = $employeedetails[0]."<br>";
echo $workname = $employeedetails[1]."<br>";
echo $workname = $employeedetails[2]."<br>";
}else{
echo "No data found";
}
?>
I hope this will help you!
Upvotes: 0
Reputation:
PHP arrays index starts from 0 not 1. then you must change this lines:
$username = $employeedetails[0];
$workname = $employeedetails[1];
Hope this help you!
Upvotes: 1