Alright, I've searched these forums and the net and cannot find anyone discussing my problem. I've been working on this forever.
What I'm trying to do: I have a car dealership that needs a website. I am using php 5 and mysqli for inventory data. I have a table for inventory details with incremental id's. I have a second table for the options on the car where the id matches the id of the car in question.
To get the id for the option to match the car I pass the id in the url from the add inventory detail page to the add options page. The add options page gets the id number ok.
The problem: I'm using checkbox inputs for the vehicle options. I'm naming them all "option" with different values, this should allow for multiple options selected, right? I'm trying to store all the options for a car as one entry on the table 'options' from what I gather the best way to do this is store them in an array. Each car will have a different number of options so it doesn't make sense to set the number of elements in the array or name them as many will often be null. I always get a foreach() error from what I understand it is because my foreach argument doesn't contain an array???
My code:
Snippet of the form:
<h4>Select All Equipped Options Below then Click Submit</h4>
<form method="post" action="<?PHP_SELF?>">
Anti Lock Brakes<input type="checkbox" name="option" value="Anti Lock Brakes" />
Dual Airbags<input type="checkbox" name="option" value="Dual Airbags" /><br />
Power Windows<input type="checkbox" name="option" value="Power Windows" />
<input type="submit" name="submit" value="Click Here to Add Options" />
<input type="hidden" name="addoption" value="1" />
My php that should access this and echo an array, but is returning a foreach error:
if ($addoption == 1) {
$opt = $POST['option'];
$caropt = array("option"=>$caropt);
foreach($opt as $caropt);
$ids = $GET['id'];
echo $ids." and ".$opt." and ".$caropt;
}
what this currently echos is - the id number and one of the selected options and "Array"
but I'm sure those of you who can help me already knew that
Back when I had my INSERT INTO code involved it would insert the id number but nothing under the option field, I removed that to try to figure this out with echo, the error is always the same
The Exact error is: Invalid argument supplied for foreach() in ...etc.etc
Now, I know my php is probably a long way from correct but I've tried so many different things, and it's 12:30 now and I'm just to tired to keep looking on the net for the answer. I just can't wrap my head around this php very well. My add inventory page works okay although I'm sure it could be better written. I've only been doing this about a week so I really don't even know what I'm talking about, but I really want to learn this. Any help or advice/links would be greatly appreciated.
Thanks for any help.