Click to See Complete Forum and Search --> : Html Checkbox


nealios
11-22-2007, 06:18 AM
Hello,

I have a single check box that will enable me to see whether to mark off if someone has paid there bill or not. The checkbox is part of a submit form that i can extract and add to my database using php and mysql.

I have set the checkbox up in the same way i would any other input text box.

Paid<input name =\"paid\" type=\"checkbox\" value=\"{$row['paid']}\" />

The db datatype is set up as Tinyint (1)

However i cant seem to get it into the db. Any pointers?


Many thanks


My form code is below



<form name=\"record_mod\" method=\"post\" action=\"jobadmin.php\">
<table border=\"1\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>
<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td align=\"left\">JobID: {$row['JobID']}</td>
</tr>
</table>

<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
<tr>
<td width=\"75\" align=\"right\">Start Date:</td>

<td colspan=\"3\">

<input id=\"demo3\" type=\"text\" name=\"StartDate\" size=\"25\" value=\"{$row['StartDate']}\">
<a href=\"javascript:NewCal('demo3','ddmmyyyy')\"><img src=\"cal.gif\" width=\"16\" height=\"16\" border=\"0\"></a>




</tr>
<tr>
<td width=\"75\" align=\"right\">End Date:</td>
<td><input id=\"demo4\" type=\"text\" name=\"EndDate\" size=\"25\" value=\"{$row['EndDate']}\">
<a href=\"javascript:NewCal('demo4','ddmmyyyy')\"><img src=\"cal.gif\" width=\"16\" height=\"16\" border=\"0\"></a></td></tr>
<td>Job Address 1:</td>

<td><input name=\"JobAddress1\" type=\"text\" size=\"30\" maxlength=\"20\" value=\"{$row['JobAddress1']}\" /></td>
<td>Job Address 2:</td>
<td><input name=\"JobAddress2\" type=\"text\" size=\"30\" maxlength=\"20\" value=\"{$row['JobAddress2']}\" /></td>
</tr>
</table>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
<tr>
<td width=\"75\" align=\"right\">Postcode:</td>
<td><input name=\"JobPostcode\" type=\"text\" size=\"40\" maxlength=\"25\" value=\"{$row['JobPostcode']}\" /></td>
</tr>
<tr>
<td width=\"75\" align=\"right\">Price :</td>
<td><input name=\"Price\" type=\"text\" size=\"40\" maxlength=\"25\" value=\"{$row['Price']}\" /></td>
</tr>
</table>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
<tr>
<td width=\"75\" align=\"right\">Description:</td>
<td><input name=\"Description\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['Description']}\" /></td>
<td>Materials:</td>
<td><input name=\"Materials\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['Materials']}\" /></td>
<td>Customer Id:</td>

<td><input name=\"cid\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['cid']}\" /></td>
<tr> <td>First Name:</td>
<td><input name=\"first_name\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['first_name']}\" /></td></tr><td>surname:</td>
<td><input name=\"surname\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['surname']}\" /></td>
<td>Paid<input name =\"paid\" type=\"checkbox\" value=\"{$row['paid']}\" /></td>




</table>

<hr align=\"left\" width=\"650\">
<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td align=\"left\">Process</td>
</tr>
</table>
<table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
<tr>
<td><input name=\"op\" type=\"radio\" value=\"1\" />&nbsp;Update Record</td>
<td><input name=\"op\" type=\"radio\" value=\"2\" />&nbsp;New Record</td>
<td><input name=\"op\" type=\"radio\" value=\"3\" />&nbsp;DELETE Record</td>
</tr>
</table>
<table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
<tr>
<td colspan=\"3\"><a href=\"#\" onclick=\"record_mod.submit()\" class=\"button\"><span class=\"icon\"> Submit </span><a></td>



<td><a href=\"jobs.php\" class=\"button\" span class=\"icon\"> Records List </span></a></td>
<td><a href=\"jobadmin.php?JobID=0&amp;op=4\" class=\"button\" span class=\"icon\"> Synchronize</span></a></td>
<td style=\"padding-left: 50px;\">
<td> <a href=\"jobadmin.php?JobID=$JobID&amp;op=5&amp;move=2\" class=\"button\" span class=\"icon\">Previous</span></a></td><td>Navigate</td>
<td> <a href=\"jobadmin.php?JobID=$JobID&amp;op=5&amp;move=1\" class=\"button\" span class=\"icon\">Next</span></a></td>
</td>
<td><a href=\"invoice.php?JobID={$row['JobID']}\" class=\"button\" span class=\"icon\"> Create Invoice </span></a></td>
</tr>
</table>
</td>
</tr>
</table></p>
<input name=\"JobID\" type=\"hidden\" value=\"$JobID\" />
</form>";

Fang
11-22-2007, 07:17 AM
How are you checking if paid returns a value server side?
Are you then placing it's value in the database or a boolean value?

nealios
11-22-2007, 07:55 AM
Ive been looking in my phpadmin to see whether the paid checkbox is going into my database.

I set up the paid field to be Tinyint (1) in the database, i thought this was a boolean data type?

// need a record number, or this script won't run
if( isset($_GET['JobID']) && is_numeric($_GET['JobID']) ) {
$JobID = intval($_GET['JobID']);
} elseif ( isset($_POST['JobID']) && is_numeric($_POST['JobID']) ) {
$JobID = intval($_POST['JobID']);
} else {
abort_script('You cannot access this script directly...', '');
}

// Is there an action requested, or just display the record?
if( isset($_POST['op']) && is_numeric($_POST['op']) ) {
$op = intval($_POST['op']);
} elseif ( isset($_GET['op']) && is_numeric($_GET['op']) ){
$op = intval($_GET['op']);////////eh
} else {
unset($op);
}
if ( $op ) {
switch( $op ) {
case 1:
modify_record($JobID);
break;
case 2:
new_record();
break;
case 3:
confirm_delete($JobID, $_GET['del']);
die();
break;
case 4:
sync_records();
break;
case 5:
next_record($JobID, $_GET['move']);
break;
default:
abort_script('Unkown error - this shouldn\'t happen...', '');
}
}



// Test our database connection
db_connect();
if ( !$result = mysql_query("SELECT * FROM customer, Job WHERE JobID = $JobID AND customer.cid = Job.cid") ) {
abort_script('Database error: ' . mysql_error(), '');
} else {
$numrows = mysql_num_rows($result);
}




// We want exactly one record
if ( $numrows === 1 ) {
send_header();
$row = mysql_fetch_array($result);
// We are posting raw data - not a good idea. Sanitizing needed here
echo"
<p>
<form name=\"record_mod\" method=\"post\" action=\"jobadmin.php\">
<table border=\"1\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>
<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td align=\"left\">JobID: {$row['JobID']}</td>
</tr>
</table>

<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
<tr>
<td width=\"75\" align=\"right\">Start Date:</td>

<td colspan=\"3\">

<input id=\"demo3\" type=\"text\" name=\"StartDate\" size=\"25\" value=\"{$row['StartDate']}\">
<a href=\"javascript:NewCal('demo3','ddmmyyyy')\"><img src=\"cal.gif\" width=\"16\" height=\"16\" border=\"0\"></a>




</tr>
<tr>
<td width=\"75\" align=\"right\">End Date:</td>
<td><input id=\"demo4\" type=\"text\" name=\"EndDate\" size=\"25\" value=\"{$row['EndDate']}\">
<a href=\"javascript:NewCal('demo4','ddmmyyyy')\"><img src=\"cal.gif\" width=\"16\" height=\"16\" border=\"0\"></a></td></tr>
<td>Job Address 1:</td>

<td><input name=\"JobAddress1\" type=\"text\" size=\"30\" maxlength=\"20\" value=\"{$row['JobAddress1']}\" /></td>
<td>Job Address 2:</td>
<td><input name=\"JobAddress2\" type=\"text\" size=\"30\" maxlength=\"20\" value=\"{$row['JobAddress2']}\" /></td>
</tr>
</table>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
<tr>
<td width=\"75\" align=\"right\">Postcode:</td>
<td><input name=\"JobPostcode\" type=\"text\" size=\"40\" maxlength=\"25\" value=\"{$row['JobPostcode']}\" /></td>
</tr>
<tr>
<td width=\"75\" align=\"right\">Price :</td>
<td><input name=\"Price\" type=\"text\" size=\"40\" maxlength=\"25\" value=\"{$row['Price']}\" /></td>
</tr>
</table>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
<tr>
<td width=\"75\" align=\"right\">Description:</td>
<td><input name=\"Description\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['Description']}\" /></td>
<td>Materials:</td>
<td><input name=\"Materials\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['Materials']}\" /></td>
<td>Customer Id:</td>

<td><input name=\"cid\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['cid']}\" /></td>
<tr> <td>First Name:</td>
<td><input name=\"first_name\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['first_name']}\" /></td></tr><td>surname:</td>
<td><input name=\"surname\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['surname']}\" /></td>
<td>Paid<input name =\"paid\" type=\"checkbox\" value=\"{$row['paid']}\" /></td>





</table>

<hr align=\"left\" width=\"650\">
<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td align=\"left\">Process</td>
</tr>
</table>
<table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
<tr>
<td><input name=\"op\" type=\"radio\" value=\"1\" />&nbsp;Update Record</td>
<td><input name=\"op\" type=\"radio\" value=\"2\" />&nbsp;New Record</td>
<td><input name=\"op\" type=\"radio\" value=\"3\" />&nbsp;DELETE Record</td>
</tr>
</table>
<table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
<tr>
<td colspan=\"3\"><a href=\"#\" onclick=\"record_mod.submit()\" class=\"button\"><span class=\"icon\"> Submit </span><a></td>



<td><a href=\"jobs.php\" class=\"button\" span class=\"icon\"> Records List </span></a></td>
<td><a href=\"jobadmin.php?JobID=0&amp;op=4\" class=\"button\" span class=\"icon\"> Synchronize</span></a></td>
<td style=\"padding-left: 50px;\">
<td> <a href=\"jobadmin.php?JobID=$JobID&amp;op=5&amp;move=2\" class=\"button\" span class=\"icon\">Previous</span></a></td><td>Navigate</td>
<td> <a href=\"jobadmin.php?JobID=$JobID&amp;op=5&amp;move=1\" class=\"button\" span class=\"icon\">Next</span></a></td>
</td>
<td><a href=\"invoice.php?JobID={$row['JobID']}\" class=\"button\" span class=\"icon\"> Create Invoice </span></a></td>
</tr>
</table>
</td>
</tr>
</table></p>
<input name=\"JobID\" type=\"hidden\" value=\"$JobID\" />
</form>";



send_footer();
} else {
// We didn't get one record - sorry!
$msg2 = "<p>
--> <a href=\"jobs.php\">Click here to return to viewing records</a> <--</p>";
abort_script('No such record found in database!', $msg2);
}

Fang
11-22-2007, 09:53 AM
None of this checks if a paid name/value is returned. :confused:

nealios
11-22-2007, 10:03 AM
Sorry i didnt explain my first problem. I thought i had done enough to check it.

How can i check whether it is check or not?

Fang
11-22-2007, 10:06 AM
Check if a paid name/value is returned