I have a form generated by taking some selected records from the database. Against each record I have added a checkbox for user to select for deletion. If I can assign the serial number of the record to each checkbox, I will know which records have to be deleted. How do I add serial number , which is available in the database, to the following HTML line ? <INPUT TYPE="CHECKBOX" NAME="check[]" value=( here I want the serial number picked up from the database ) > Is there a standard simple method in PHP ? I have tried the following which does not work. <INPUT TYPE="CHECKBOX" NAME="check[]" value=<?php $_SESSION["xyz"] ?>>
Assuming $_SESSION["xyz"] contains your serial number, use <?php echo $_SESSION["xyz"]; ?> PHP: echo displays whatever is in the varaible $_SESSION["xyz"].
Thank you Mr.MathewRobertBell, that is perfectly okay. But my question was about assigning "value" to the checkbox in the Line, < INPUT TYPE=CHECKBOX NAME="delete" VALUE=?> In place of the ? I want a variable to be inserted as value to the check box so that I can read it in another php file. This value is supposed to come from a table in the database. Can you help ?
You need to get the data from the database into a variable, then you can insert it into your html using the code i mentioned earlier.
I Thank you all for very quick and precise solution. Declaring value using echo ( which I was missing ) has worked like magic! Looking forward for further help on my journey to learning php ! Chiplonkar
Your suggestion of inserting echo statement inside the value for assigning the value to any check box worked fine !. But, now I have another difficulty. The reading back of assigned values in another php page worked okay till the assigned values were less than "10" i.e. single digit. After the assigned value( which is a serial number of my record ) becomes more than " 9 ", the reading back gives me only first digit. The code is as under . These three lines are supposed to extract checkbox array value and show it on the screen. ( for diagnosis of fault ) foreach($_POST["checkbox"] as $val){ echo "value of selected box is =".$val; } Where is the mistake ? The checkbox is declared as an array checkbox[]. Therefore, I am trying to read all checked boxes by "foreach" statement. Thanks, Chiplonkar