Alright, I’m making a website using PHP/HTML, and I have some backend AJAX to auto generate some checkboxes with data based on a drop down menu selection earlier in the page.
Basically here is the process…
->Select a Job Name (JobXYZ) from a drop down menu
->Checkboxes are automatically generated (pulled from a databse), anywhere from 0-10+ can be created, they are of car names associated with the selected job.
Here is the little code snippet that generates these checkboxes…
$sql = "SELECT Description FROM Cars WHERE JobNumber='$JobNumber'";
$rs = odbc_exec($connection, $sql);
while(odbc_fetch_row($rs)) {
$rowCarDeets = odbc_result($rs, 'Description');
$response = $response . "<input type='checkbox' name='CarDescription' value='" . $rowCarDeets . "'>". $rowCarDeets . "</input></br>";
}
As you can see, the checkboxes are all called ‘CarDescription’ and then the value is filled in. When the website is actually created and these checkboxes are created, I can confirm via inspecting these elements on the webpage that they do have the name ‘CarDescription’ with varying values that are the correct values. What I’m saying is that the auto creation of these checkboxes works as intended.
They are all a part of a form that is submitted along with several other things that get submitted via a ‘post’ at the click of a submit button.
From there I go to my form submit php file and I simply grab everything that has been posted like so…
$Variable=$_POST[‘VariableName’];
I try to do it with car description as I do everything else…
$CarDescription=$_POST[‘CarDescription’]; but it doesn’t work. There are two issues here…
-
Even if I select just one checkbox and submit it, nothing goes through. Based on my work with other checkboxes, checkboxes with the same name but different values should still get posted if only one is selected. That isn’t the case here.
-
I will need to be able to select multiple checkboxes in the future, how can I deal with this? Is there a way to post something as an array of checkbox values or something of that nature? Before I deal with this problem though I figure I should fix the issue I am having with just properly sending any data at all (from a single checkbox).
Your help would be greatly appreciated!
EDIT: This information doesn’t even seem to be getting posted. Even if I make it into an array I get the following warning:
Notice: Undefined index: CarDescription in C:\---submit_form.php on line 26
This here is line 26….
$CarDescription=$_POST['CarDescription'];
Again, this happens if I make it an array, make tons of changes to it, etc.
On this line:
Change the name field to
name=CarDescription[]. They are then accessible in PHP as an array. Run this to see what it contains:print_r($_POST["CarDescription"])