johnnys Posted June 13, 2013 Share Posted June 13, 2013 Hi, I need some help with a table on my website. Apologies for my lack of knowledge, I'm quite new to php, and I have been researching this problem for days now. I'm not even sure if I'm doing this the correct way? My webform contains two fields (amongst others) - code below <div class="controls"> <input type="checkbox" id="wallbox_needs_patched" value="1" name="wallbox_needs_patched"> Please tick this box if you would like blah blah. </div> <div class="controls"> <label class="control-label" for="reason">Reason Details</label> Tell us your reason blah blah. </div> I also have this php code relating to the wallbox_needs_patched field - code below if(isset($_REQUEST['wallbox_needs_patched']) && $_REQUEST['wallbox_needs_patched']==1 ){ $isWallboxPatchReqd=1; }else{ $isWallboxPatchReqd=0; } The table code that I send to the user also works well - code below <table> <tbody> <tr> <td>Wall Box Patch?:</td> <td>".$isWallboxPatchReqd."</td> </tr> <tr> <td>Reason?:</td> <td>".$reason."</td> </tr> </tbody> </table> This successfully sends the form to the user, and if the checkbox is 'checked' for the wallbox field it sends a '1' in the form otherwise a '0' is sent. I have two questions, in the email that is sent to the user how do I send a 'Yes' and 'No' instead of a '1' or '0' respectively. Also, if the 'reason' field is left blank (not filled in by the user), how do I insert 'N/A' into the form which is sent to them instead of it showing a blank field. Thanks in advance, and again excuse my ignorance. Taking this project over from somebody else. J Quote Link to comment https://forums.phpfreaks.com/topic/279110-table-fields-if-null/ Share on other sites More sharing options...
Barand Posted June 13, 2013 Share Posted June 13, 2013 I showed you how in your similar post yesterday http://forums.phpfreaks.com/topic/279073-checkbox-values/?do=findComment&comment=1435557 Quote Link to comment https://forums.phpfreaks.com/topic/279110-table-fields-if-null/#findComment-1435710 Share on other sites More sharing options...
johnnys Posted June 13, 2013 Author Share Posted June 13, 2013 Hi, Yes apologies for starting another thread, I thought it worked and was solved but it actually didnt! I followed your steps, firstly I got the error below on my webpage when trying to send the form - below SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0, Then remembering your advice, I changed my database field from tinyint to varchar and then the above message disappeared, but a new one appeared - below SQLSTATE[42S22]: Column not found: 1054 Unknown column 'yes' in 'field list' This is as far as I am now, Thanks Quote Link to comment https://forums.phpfreaks.com/topic/279110-table-fields-if-null/#findComment-1435720 Share on other sites More sharing options...
Barand Posted June 13, 2013 Share Posted June 13, 2013 String values in a query need to be quoted thus '$isWallboxPatchReqd', otherwise sql assumes they are column names Quote Link to comment https://forums.phpfreaks.com/topic/279110-table-fields-if-null/#findComment-1435722 Share on other sites More sharing options...
johnnys Posted June 13, 2013 Author Share Posted June 13, 2013 I appreciate your help Barand, but I'm not too sure what I should enclose in quotes, all variations I have tried don't seem to work. Thanks anyway Quote Link to comment https://forums.phpfreaks.com/topic/279110-table-fields-if-null/#findComment-1435730 Share on other sites More sharing options...
johnnys Posted June 13, 2013 Author Share Posted June 13, 2013 I finally got it working Thank you.. One last thing.. now when the email sends, it's leaving out everything after where i placed the code? See below <tr> <td>Wall Box Patch?:</td> <td>".$isWallboxPatchReqd = isset($_REQUEST['wallbox']) ? 'yes' : 'no';"</td> </tr> <tr> <td>Setup Request?:</td> <td>".$isSetupHelpReqd."</td> </tr> <tr> <td>Reason For Setup?:</td> <td>".$reason."</td> </tr> </tbody> </table> <p> thank you for blah blah </p> So everything after the 'Wall Box Patch' field is missing (although the code works!) Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/279110-table-fields-if-null/#findComment-1435742 Share on other sites More sharing options...
Barand Posted June 13, 2013 Share Posted June 13, 2013 Set the value before outputting the table $isWallboxPatchReqd = isset($_REQUEST['wallbox']) ? 'yes' : 'no'; .... echo "<td>$isWallboxPatchReqd</td>"; .... Quote Link to comment https://forums.phpfreaks.com/topic/279110-table-fields-if-null/#findComment-1435747 Share on other sites More sharing options...
johnnys Posted June 13, 2013 Author Share Posted June 13, 2013 ah i give up! I can now see the rest of my email just fine thanks to your instructions but it always posts a 'yes' whether the checkbox is ticked or not?! never a 'no' when unchecked. I've also added a 'hidden' checkbox field to my html form, I've seen online this can also help return unchecked values. see code below - <input type="hidden" id="wallbox" value="0" name="wallbox"> <input type="checkbox" id="wallbox" value="1" name="wallbox"> thanks again Quote Link to comment https://forums.phpfreaks.com/topic/279110-table-fields-if-null/#findComment-1435751 Share on other sites More sharing options...
Solution Barand Posted June 13, 2013 Solution Share Posted June 13, 2013 Now you have added the hidden field, $_POST['wallbox'] is always set, that's why it is always yes. You now need to check if it is equal to 1 instead of checking isset() Quote Link to comment https://forums.phpfreaks.com/topic/279110-table-fields-if-null/#findComment-1435752 Share on other sites More sharing options...
johnnys Posted June 13, 2013 Author Share Posted June 13, 2013 thank you! working Quote Link to comment https://forums.phpfreaks.com/topic/279110-table-fields-if-null/#findComment-1435760 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.