Hi All,
I have been able to insert a checkbox value into my database. The problem i am now facing is how to retrieve the value of the checkbox in the form of a TICK.
Your help will be much appreciated.
Regards.
Retrieving checkboxes values from mysql
Moderator: General Moderators
-
sockpuppet
- Forum Newbie
- Posts: 22
- Joined: Tue Jan 18, 2011 8:38 am
Re: Retrieving checkboxes values from mysql
Use an IF statement.
if the value of the tick box is what is in the database then echo "checked" into the <input> html.
if the value of the tick box is what is in the database then echo "checked" into the <input> html.
Re: Retrieving checkboxes values from mysql
This is my sample code and its not working.
can you please help me out.
regards.
Code: Select all
$sql = "SELECT * FROM samoa WHERE samoa.entryid = '$entryid'";
$result = mysql_query($sql);
if ($row = @mysql_fetch_array($result, MYSQL_ASSOC)) {
print "<form name=\"formname\" method=\"post\" action=\"$_SERVER[PHP_SELF]\">";
echo" <table width=\"881\" border=\"1\" align=\"center\">
<tr>
<td colspan=\"1\">Status:</td>>
<td><input name=\"status\" id=\"status\" value=\"$row[status]\" READONLY/></td>
</tr>
<tr>
<td><input type=\"checkbox\" name=\"final\" [b]value=\"final\" [/b]id=\"final\" CHECKED/></td>
</tr>
</table>";regards.
-
sockpuppet
- Forum Newbie
- Posts: 22
- Joined: Tue Jan 18, 2011 8:38 am
Re: Retrieving checkboxes values from mysql
Ok, first use ' with strings it will mean that you don't have to escape each " with a \ when writing html.
This should work, buts its untested.
This should work, buts its untested.
batowiise wrote:This is my sample code and its not working.
can you please help me out.Code: Select all
$sql = "SELECT * FROM samoa WHERE samoa.entryid = '$entryid'"; $result = mysql_query($sql); if ($row = @mysql_fetch_array($result, MYSQL_ASSOC)) { print "<form name=\"formname\" method=\"post\" action=\"$_SERVER[PHP_SELF]\">"; echo" <table width=\"881\" border=\"1\" align=\"center\"> <tr> <td colspan=\"1\">Status:</td>> <td><input name=\"status\" id=\"status\" value=\"$row[status]\" READONLY/></td> </tr> <tr>"; if($row['final'] == "final") { $checked = "CHECKED"; } else { $checked = ""; } print "<td><input type=\"checkbox\" name=\"final\" value=\"final\" id=\"final\" " . $checked . "/></td> </tr> </table>";
regards.
Re: Retrieving checkboxes values from mysql
That was a cracker. It did solve my problem. Thanks.