Page 1 of 1
Retrieving checkboxes values from mysql
Posted: Mon Jan 24, 2011 9:18 am
by batowiise
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.
Re: Retrieving checkboxes values from mysql
Posted: Mon Jan 24, 2011 9:45 am
by sockpuppet
Use an IF statement.
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
Posted: Mon Jan 24, 2011 9:53 am
by batowiise
This is my sample code and its not working.
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>";
can you please help me out.
regards.
Re: Retrieving checkboxes values from mysql
Posted: Mon Jan 24, 2011 10:05 am
by sockpuppet
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.
batowiise wrote:This is my sample code and its not working.
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>";
can you please help me out.
regards.
Re: Retrieving checkboxes values from mysql
Posted: Mon Jan 24, 2011 10:17 am
by batowiise
That was a cracker. It did solve my problem. Thanks.