Best way to use checkboxes with PHP

hisseriobogue

New Member
first off I am a rookie so please forgive my basic question. I am trying to use an html checkbox to let me know when to check a serial number. The problem is no matter what i do I get an error telling me "Notice: Undefined index: sncheck in XYZ".I tried using a ternary operator to set the value as it was posted (If the checkbox was not checked) but it still fails on me. Any suggestions would be Here is the code, below im using a checkbox with the name sncheck and a value of ok. thanks!\[code\]if (isset($_POST['submit'])){ $gov = mysqli_real_escape_string( $dbc, trim($_POST['gov'])); $pctype = mysqli_real_escape_string( $dbc, trim($_POST['pctype'])); $compname = mysqli_real_escape_string( $dbc, trim($_POST['compname'])); $username = mysqli_real_escape_string( $dbc, trim($_POST['username'])); $compmodel = mysqli_real_escape_string( $dbc, trim($_POST['compmodel'])); $serialnumber = mysqli_real_escape_string( $dbc, trim($_POST['serialnumber'])); $sncheck = ($_POST['sncheck']== 'ok') ? $_POST['sncheck'] : ''; $purchdate = mysqli_real_escape_string( $dbc, trim($_POST['purchasedate'])); $os = mysqli_real_escape_string( $dbc, trim($_POST['os'])); $memory = mysqli_real_escape_string( $dbc, trim($_POST['memory'])); $monitor1 = mysqli_real_escape_string( $dbc, trim($_POST['monitor1'])); $monitor2 = mysqli_real_escape_string( $dbc, trim($_POST['monitor2'])); $warranty = mysqli_real_escape_string( $dbc, trim($_POST['warranty'])); $warrantyend = mysqli_real_escape_string( $dbc, trim($_POST['warrantyend'])); $status = mysqli_real_escape_string( $dbc, trim($_POST['status'])); $notes = mysqli_real_escape_string( $dbc, trim($_POST['notes'])); if (dateformat($purchdate) == 1 && $sncheck == "ok"){ $querysn = "SELECT serialnumber FROM inventory" . " WHERE serialnumber = '" . $serialnumber . "'"; $data = http://stackoverflow.com/questions/3621075/mysqli_query($dbc, $querysn) or die('Error querying the Database for Serial Numbers'); if (mysqli_num_rows($data) == 0){ $queryupdate = "UPDATE inventory SET government = '$gov', pctype = '$pctype', compname = '$compname'," . " username = '$username', compmodel = '$compmodel', serialnumber = '$serialnumber', purchased = '$purchdate'," . " operatingsystem = '$os', `memory` = '$memory', monitor1 = '$monitor1'," . " monitor2 = '$monitor2', warranty = '$warranty', warrantyend = '$warrantyend', `status` = '$status', notes = '$notes'" . " WHERE serialnumber = '" . $_POST['serialnumber'] . "'"; mysqli_query($dbc, $queryupdate); echo 'PC was sucessfully saved'; } else{ echo '<p class="error">The serial number has already been used, please try another</p>'; } } else{ echo '<p class="error">The date format does not match</p>'; } if (dateformat($purchdate) == 1){ $querysn = "SELECT serialnumber FROM inventory" . " WHERE serialnumber = '" . $serialnumber . "'"; $data = http://stackoverflow.com/questions/3621075/mysqli_query($dbc, $querysn) or die('Error querying the Database for Serial Numbers'); if (mysqli_num_rows($data) == 0){ $queryupdate = "UPDATE inventory SET government = '$gov', pctype = '$pctype', compname = '$compname'," . " username = '$username', compmodel = '$compmodel', purchased = '$purchdate'," . " operatingsystem = '$os', `memory` = '$memory', monitor1 = '$monitor1'," . " monitor2 = '$monitor2', warranty = '$warranty', warrantyend = '$warrantyend', `status` = '$status', notes = '$notes'" . " WHERE serialnumber = '" . $_POST['serialnumber'] . "'"; mysqli_query($dbc, $queryupdate); echo 'PC was sucessfully saved'; } else{ echo '<p class="error">The serial number has already been used, please try another</p>'; } } else{ echo '<p class="error">The date format does not match</p>'; }}\[/code\]
 
Back
Top