close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Update Not Working Correctly

Thread began 12/17/2018 11:27 am by LWat85283715 | Last modified 12/17/2018 12:46 pm by Ray Borduin | 43 views | 7 replies |

LWat85283715

Update Not Working Correctly

For some reason if I uncheck a checkbox, it won't save that it is now unchecked. But, if there is a checkbox group, it will remember that it is unchecked as long as there is one checked. Here is my code:

<?php
if (isset($_POST["submit"]) || isset($_POST["submit_x"])) {
$UpdateQuery = new WA_MySQLi_Query($sdpc_i);
$UpdateQuery->Action = "update";
$UpdateQuery->Table = "`data`";
$UpdateQuery->bindColumn("districtID", "i", "".((isset($_POST["districtID"]))?$_POST["districtID"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("softwareID", "i", "".((isset($_POST["softwareID"]))?$_POST["softwareID"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("agreement_typesID", "i", "".((isset($_POST["agreement_typesID"]))?$_POST["agreement_typesID"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("agreement_file", "s", "".(((isset($_FILES["agreement_file"]))? preg_replace('/.[^.]*$/', '', $_FILES["agreement_file"]["name"]) :"")) ."", "WA_IGNORE");
$UpdateQuery->bindColumn("signed_agreement_file", "s", "".(((isset($_FILES["signed_agreement_file"]))? preg_replace('/.[^.]*$/', '', $_FILES["signed_agreement_file"]["name"]) :"")) ."", "WA_IGNORE");
$UpdateQuery->bindColumn("statusID", "i", "".((isset($_POST["statusID"]))?$_POST["statusID"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("date_approved", "t", "".((isset($_POST["date_approved"]))?$_POST["date_approved"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("date_expired", "t", "".((isset($_POST["date_expired"]))?$_POST["date_expired"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("requestor", "s", "".((isset($_POST["requestor"]))?$_POST["requestor"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("requestor_email", "s", "".((isset($_POST["requestor_email"]))?$_POST["requestor_email"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("school", "s", "".((isset($_POST["school"]))?implode(", ",$_POST["school"]):"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("year", "s", "".((isset($_POST["year"]))?$_POST["year"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("grade_level", "s", "".((isset($_POST["grade_level"]))?implode(", ",$_POST["grade_level"]):"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("content_area", "s", "".((isset($_POST["content_area"]))?implode(", ",$_POST["content_area"]):"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("cost", "s", "".((isset($_POST["cost"]))?$_POST["cost"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("paid_by", "s", "".((isset($_POST["paid_by"]))?$_POST["paid_by"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("media_release", "s", "".((isset($_POST["media_release"]))?$_POST["media_release"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("declined_reasoning", "s", "".((isset($_POST["declined_reasoning"]))?$_POST["declined_reasoning"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("notes", "s", "".((isset($_POST["notes"]))?$_POST["notes"]:"") ."", "WA_IGNORE");
$UpdateQuery->bindColumn("request_submitted_date", "t", "".((isset($_POST["request_submitted_date"]))?$_POST["request_submitted_date"]:"") ."", "WA_IGNORE");
$UpdateQuery->addFilter("dataID", "=", "i", "".($_GET['dataID']) ."");
$UpdateQuery->execute();
$UpdateGoTo = "manage_agreements.php?state=" . $_GET['state'] . "&districtID=" . $_GET['districtID'] . "";
if (function_exists("rel2abs")) $UpdateGoTo = $UpdateGoTo?rel2abs($UpdateGoTo,dirname(__FILE__)):"";
$UpdateQuery->redirect($UpdateGoTo);
}
?>

Checkbox code looks like this:

<input <?php if (!(strcmp($district_data->getColumnVal("media_release"),"Yes"))) {echo "checked=\"checked\"";} ?> name="media_release" type="checkbox" value="Yes" aria-label="Requires Media Release">

Thanks

Sign in to reply to this post

Ray BorduinWebAssist

You have the default value set to "ignore" for that field. That means that if no value is submitted, then the update for that column is ignored. If you set it to "null" or "blank" then it will set the value to null or blank when no value is submitted.

Sign in to reply to this post

LWat85283715

So, when someone enters a new value in the form field, I want it to update it to that form field but, if there is nothing entered in the form field, I want it to ignore that field and leave whatever is in the database for that field there. So, would that be Ignore, null, or blank?

Sign in to reply to this post

Ray BorduinWebAssist

That is ignore. So if you have a checkbox and set the checkbox value to "yes"... then when someone checks the box it gets set to "yes". If they uncheck the box then no value is submitted. If it is set to "ignore", then the database "yes" value remains.

The "ignore" option is really there for the password or hashed field values. You can't or wouldn't want to pre-fill the password field for security reasons, so you want to leave the old password when the field is left blank, but update it if someone enters a value.

Usually all other fields use "blank" or "null" to allow users to update and actually put in a blank value. You could also update the default to be a string like "No", so that if the value is blank (like an unchecked box) the string "No" is placed in that field.

Sign in to reply to this post

LWat85283715

This makes sense. I will try this. Thanks

Lisa

Sign in to reply to this post

LWat85283715

I made them all WA_NULL and now none of them are updating:

<?php
if (isset($_POST["submit"]) || isset($_POST["submit_x"])) {
$UpdateQuery = new WA_MySQLi_Query($sdpc_i);
$UpdateQuery->Action = "update";
$UpdateQuery->Table = "`data`";
$UpdateQuery->bindColumn("districtID", "i", "".((isset($_POST["districtID"]))?$_POST["districtID"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("softwareID", "i", "".((isset($_POST["softwareID"]))?$_POST["softwareID"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("agreement_typesID", "i", "".((isset($_POST["agreement_typesID"]))?$_POST["agreement_typesID"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("agreement_file", "s", "".($WA_DFP_UploadStatus["WA_UploadResult1"]["WA_UploadResult1_1"]["serverFileName"]) ."", "WA_IGNORE");
$UpdateQuery->bindColumn("signed_agreement_file", "s", "".($WA_DFP_UploadStatus["WA_UploadResult1"]["WA_UploadResult1_1"]["serverFileName"]) ."", "WA_IGNORE");
$UpdateQuery->bindColumn("statusID", "i", "".((isset($_POST["statusID"]))?$_POST["statusID"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("date_approved", "t", "".((isset($_POST["date_approved"]))?$_POST["date_approved"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("date_expired", "t", "".((isset($_POST["date_expired"]))?$_POST["date_expired"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("requestor", "s", "".((isset($_POST["requestor"]))?$_POST["requestor"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("requestor_email", "s", "".((isset($_POST["requestor_email"]))?$_POST["requestor_email"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("school", "s", "".((isset($_POST["school"]))?implode(", ",$_POST["school"]):"") ."", "WA_NULL");
$UpdateQuery->bindColumn("year", "s", "".((isset($_POST["year"]))?$_POST["year"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("grade_level", "s", "".((isset($_POST["grade_level"]))?implode(", ",$_POST["grade_level"]):"") ."", "WA_NULL");
$UpdateQuery->bindColumn("content_area", "s", "".((isset($_POST["content_area"]))?implode(", ",$_POST["content_area"]):"") ."", "WA_NULL");
$UpdateQuery->bindColumn("cost", "s", "".((isset($_POST["cost"]))?$_POST["cost"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("paid_by", "s", "".((isset($_POST["paid_by"]))?$_POST["paid_by"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("media_release", "s", "".((isset($_POST["media_release"]))?$_POST["media_release"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("declined_reasoning", "s", "".((isset($_POST["declined_reasoning"]))?$_POST["declined_reasoning"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("notes", "s", "".((isset($_POST["notes"]))?$_POST["notes"]:"") ."", "WA_NULL");
$UpdateQuery->bindColumn("request_submitted_date", "t", "".((isset($_POST["request_submitted_date"]))?$_POST["request_submitted_date"]:"") ."", "WA_NULL");
$UpdateQuery->addFilter("dataID", "=", "i", "".($_GET['dataID']) ."");
$UpdateQuery->execute();
$UpdateGoTo = "manage_agreements.php?state=" . $_GET['state'] . "&districtID=" . $_GET['districtID'] . "";
if (function_exists("rel2abs")) $UpdateGoTo = $UpdateGoTo?rel2abs($UpdateGoTo,dirname(__FILE__)):"";
$UpdateQuery->redirect($UpdateGoTo);
}
?>

Sign in to reply to this post

Ray BorduinWebAssist

Does your database allow null values for all of those columns? It would fail if you try to set a null value to a column that doesn't allow null.

Sign in to reply to this post

LWat85283715

It is working now. Thanks

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...