Jump to content

Table fields if null


johnnys

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/279110-table-fields-if-null/
Share on other sites

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

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.