t4thilina t4thilina - 1 year ago 109
HTML Question

How to solve error 'Notice: Array to string conversion in.....'

I have a PHP file named with Set of HTML codes. The values for the textboxes are assigned and they prints as I needed.

echo "<html>";
echo "<body>";
for($i=0; $i<5;$i++){

echo "<input name='C[]' value='$Texting[$i]' style='background-color:#D0A9F5;'></input>";

echo "</body>";
echo "</html>";
echo '<input type="submit" value="Save The Table" name="G"></input>'

And I need to store the values of the textboxes in an array and its to another PHP file in order to send the values to the database. This is a part of other PHP file.


echo $_POST['C'];



But when Im sending it I get an error like

Notice: Array to string conversion in C:\xampp\htdocs\PHIS\FinalSubmissionOfTheFormPHP.php on line 8..
Could someone please explain me what this error is and how can I solve it out.

Answer Source

When you have many HTML inputs named C[] what you get in the POST array on the other end is an array of these values in $_POST['C']. So when you echo that, you are trying to print an array, so all it does is print Array and a notice.

To print properly an array, you either loop through it and echo each element, or you can use print_r.

Alternatively, if you don't know if it's an array or a string or whatever, you can use var_dump($var) which will tell you what type it is and what it's content is. Use that for debugging purposes only.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download