Mysql/PHP product selection form. PLEASE HELP!!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
benbenson
Forum Newbie
Posts: 2
Joined: Tue Jul 12, 2005 11:00 am

Mysql/PHP product selection form. PLEASE HELP!!

Post by benbenson »

I am reasonably new to php, and have been dropped in the deep end, by building a shopping cart site. I have just about got the majority working, by "borrowing" and changing code from friends etc.

The site is temporarily at: http://www.ecom-sys.com/ability/ability_direct.htm

you'll see that the first drop down box is populated from the DB correctly, and when changed, the second drop down populates itself with the correct values. However, when the second box is changed, even though the third box populates itself correctly, the first and second box reset themselves to wrong values. I want them to remain on the selected values as before. I've tried everything, introducing various temp variables, declaring and redeclaring, setting, and everything i can think of! but to no avail! Any help would be greatly appreciated.

the code is slightly too long to post here, but here is a link to it:

http://www.ecom-sys.com/ability/code.txt

I apologise for the long post, and the near impossible task of decyphering my code! But i would be the most grateful person in the world ever ever ever if anyone can suggest a solution! Many thanks in advance!

Kind Regards,

Ben Benson
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

since you're reloading the page, just check to see if a post var is set, if it is, then display it's value if not then display the value from the db:

ex:

Code: Select all

$bob = "<select name=\"cat1\">";
$bob .= "<option value=\"whatever\" ".(isset($_POST['cat1'] && $_POST['cat1'] == "whatever" ? "selected=\"selected\"" : "").">Whatever</option>";
$bob .= "</select>";
echo $bob;
benbenson
Forum Newbie
Posts: 2
Joined: Tue Jul 12, 2005 11:00 am

Post by benbenson »

Thanks for the reply, however, i cannot seem to get your code to work. I see what you mean, and it looks to be a much simpler way of verifying the post variable is set. But the code wont work, it doesnt like one of the brackets, or quotes, or commas, or periods, or something!

But, if it did work, and it showed that the post variable was not set when it should be, how would that be resolved, as i think this is the main problem. It seems to recognise the value being set after the first onchange function, but after the second it loses the variable and defaults to the wrong selection.

Still stuck! please help!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

check the values of the post vars you should. determine where/why you're losing them you will.

echo them out you can:

ex:

Code: Select all

echo $_POST['var1'];
Post Reply