Wierd PHP Request


I am new to this forum, but need to learn a thing or two about PHP… Now my request may be difficult or need a lot of planning to accomplish but here is what I am trying to do:

I have a form connected to the database I am working with and It pulls queries from existing table data, and on change (submit) it replaces existing data.

I now want to move forward, and do something different.

I want to essentially have checkboxes (8 total) and if any one is checked, it will add to a value (making HTML)

For example, if Checkbox 1 is selected, display [HTML DATA HERE] - Which could be anything I needed it to be
If checkbox 2 is selected, the value will add to the bottom of the last field, and this repeats for each checkbox.

The output (which I want to push into the Database) will be similar to as follows:

[HTML Checkbox1]
[HTML Checkbox2]
[HTML Checkbox3]

Again, this needs to go into the database to replace the existing field

Any takers? Can anyone point me in the right direction?

If you are talking about making a text field show when a checkbox is clicked you will need javascript for that
I you want to insert that into the db just check to see if it is there and if it is then update

Show us your code and we will help you out.

I wasn’t sure how to start doing this, and wanted suggestions on how it could be done. I want a value assigned to a checkbox and depending on what is selected have it add into the database, and essentially add a div of content per checkbox (in an order).

I will try working on this and see what my options are. I just need to be pointed in the right direction for how to begin.

Well, is your HTML that is shown when the checkbox are selected just plain HTML and not dynamic?
If so, just use JS and


You can create a section of code like this:

...some HTML code like
this is a sample
... whatever valid HTML codes

And, then use Javascript to set the display option for the

that corresponds to the checkbox.
This option is the CSS styling option “display:block” or “display:hidden”. You would just have to add in
an simple JS call in the actual checkbox code. It would be something like this:

HTML 1 Checkbox

This would create a checkbox and call a routine called check1Change that would display or hide the

as needed. In that routine, you would just do some Javascript that would read the current value of the
checkbox and hide or display the DIV… Something like this: (Oh, not tested…)

function check1Change(check1) {
if (check1.checked) {
document.getElementById(“yourDIVname”).style.display = “block”;
document.getElementById(“yourDIVname”).style.display = “none”;

Something like that would show/hide a

by selecting a checkbox. The code was mostly just off
the top of my mind, so untested… Once you get some code, show us and we can help fix it up…

good luck

Here is what I have so far. Now I have a problem passing the variable through to the next step.

This is the JQuery/HTML section:

Fill the form:

Phone Support: Yes No

Live Chat Support:

Yes No

Live Meeting:

Yes No
Remote Support: Yes No
Ticket By Portal: Yes No

Ticket By Email:

Yes No

Ticket By Voicemail:

Yes No

Ticket By Fax:

Yes No

This is the PHP section.

if(isset($_POST[‘Sphone’]) && isset($_POST[‘Schat’]) && isset($_POST[‘Smeet’]) && isset($_POST[‘Sremo’]) && isset($_POST[‘Sport’]) && isset($_POST[‘Smail’]) && isset($_POST[‘Svoic’]) && isset($_POST[‘Sfax’])) {
$_POST = array_map(“strip_tags”, $_POST); // Gets rid of tags in POST Call

// get data
$Sphone = $_POST[‘Sphone’];
$Schat = $_POST[‘Schat’];
$Smeet = $_POST[‘Smeet’];
$Sremo = $_POST[‘Sremo’];
$Sport = $_POST[‘Sport’];
$Smail = $_POST[‘Smail’];
$Svoic = $_POST[‘Svoic’];
$Sfax = $_POST[‘Sfax’];

// Define Full Output of variable
$arrow =’’.$Sphone.’
function passVariable($arrow)
return $arrow or die(mysql_error());
echo $arrow;


I did have more code above this, just the database connection, etc.

This works fine to change the variables. Right now I have Pen 1, Pen 2, etc… as placeholders (with a break in between).

Now my only issue is passing the variables (to move this to another section of the code)

I want to keep all of this into one file. I tested this with a variable named $arrow and it will not echo this variable (added a DIE error to it also) - any takers?

Well, first, is this file named “script.php”???

Trying to understand the “flow” of your program. First, remember that all PHP is handled server-side and does not exist once you have it inside the browser. (ALL PHP code is gone once inside the browser!) This is important to remember as Javascript, JQuery, etc can have NO access to any PHP code. Therefore, you can “read” values set by PHP, but, can not alter them. You CAN alter the data with JS and you can save the data.

So, I am not clear on your needs, but, a checkbox is the same as an option/select clause. You would just use a standard HTML checkbox and have PHP load the value from the database. Something like this:

I own a home!
I have a car.
I have a bicycle!
The value of each would be whatever you want. Using a database, you would pull the data from the table and place it into the checkbox so the current value is whatever is in your database. Since checkboxes only have two options, CHECKED or NOT-CHECKED. So, the data can be yes/no, 0/1, Own-a-Home/No-Home, whatever you need for your set up. Then, the data is entered as the PHP builds the checkbox tag. Something like: $house = SomeResultsFromDB; if($house=="default-for-house"){ $checked="" }else{ $checked="checked=checked"; } //This "IF" basically sets the checked value to null or checked... echo "" This is just an example on how to display a checkbox from the database data. You have to set the values and tell it if it is checked or not. Quite simple.

Then, when you show the form, the user can check/uncheck the current value that was pulled from the database. And, then when they submit the data, you just pull the checkbox and save the new value.

Is that what you needed? Good luck…


that is an example of what I have done. I need to pass the variable to the above statement. I do have a secondary file called script.php however.

The PHP inside this is the same PHP from above. I tried to move this into the same file… but unsure of how.

See how the above works? I want to be able to call that variable in the above textarea.

Also, I just changed script.php to jq.php and see how wierd the echo result is?

I separated the two (one uses script.php and the other uses jq.php)

http://catalyst.mspwebsite.com/jq.php - jq.php

http://catalyst.mspwebsite.com/jq1.php - script.php

Okay, first, let’s start with your samples you just posted… It appears your code is working as you did
program it. But, I think it is NOT what you wanted it to do. Let’s explain so you are clear, or we both are…

You are using “drop-down” select clauses, NOT checkboxes as you mentioned. The drop-downs are okay,
but, for a yes, no option, I think that a real checkbox nicer. (add a title “Select support options you wish”)
You should consider changing them to radio’s… But, for this discussion, let’s leave them as drop-down’s.

So, let’s talk about the “phone-support” one only. It has two options, either yes or no. Once this is in the
browser, the user will see the default, usually the first option but can be whichever you set it to be.
It’s code:
Phone Support:

Yes No
[/php] So, this code set's the default to be "Pen1" and shows the user "Yes". Once the submit button is pressed, the page "POSTS" this data to the form's submit page. At this point each SEPARATE select clause has a value which can be read. Such as "Sphone". In this case, it can be either NULL ("") or "Yes". Since these are the two value you placed into the options for this select. One problem with this is that if they select "No", then nulls are involved. When the "data" for the option is read, it may be set to null and you can not use that value. Reading the "value", such as in PHP, $Sphone=$_POST['Sphone']; may give you an error. You can do it in this manner: if(isset($_POST['Sphone'])) {do something...} This will check if null and if not it will let you do something. If you are saving your data inside a database, it is usually better to use real data for each option and then you can just capture the values and not have to test for NULLs. Either way will work. But, you must know which way you are handling it.

Therefore, in this section of your code:
if(isset($_POST[‘Sphone’]) && isset($_POST[‘Schat’]) && isset($_POST[‘Smeet’]) && isset($_POST[‘Sremo’]) && isset($_POST[‘Sport’]) && isset($_POST[‘Smail’]) && isset($_POST[‘Svoic’]) && isset($_POST[‘Sfax’])) {
$_POST = array_map(“strip_tags”, $_POST); // Gets rid of tags in POST Call

// get data
$Sphone = $_POST[‘Sphone’];
You are testing for all your fields and if they are all set, you get the data. This will never work because you
are using nulls for the “NO” version of the options in the select tags. If, let’s say, the user does not select
“Sport”, then the if statement will NEVER be valid as the “Sport” value will be null and NOT be set. And, this
would make the IF to be false. So, most likely you just have to change all your options to include Yes/No
instead of Yes/NULL. Also, normally, this would be a list of options that would be selected not a drop-down.
So, normally it would be something like:
Select your support options you wish to use:
Phone Support

Live Chat Support

Email Support

Something like that. Then, the all of the options would be inside an array called “options”. In PHP, you
could then loop thru the options and all checkboxes that are “CHECKED” would be in the array. If array is
empty, then, no options were checked. You can just store the entire array into your database and load it
back in as needed to display the options that the user previously selected.

Well, not sure if all of this helped or not. If not, please ask further questions…

Sponsor our Newsletter | Privacy Policy | Terms of Service