yogibear Posted January 21, 2007 Share Posted January 21, 2007 Hi allI have been stuck on this annoying problem for a while and tried a few different things trying to fix it but nothing seems to work.I have a drop down menu with a list of cars when a user selects one of the cars it is inserted into the database but I also want it to insert some other information that the user would never see or atleast not be able to edit.Something like this:[table][tr][td][table][tr][td]Car (dropdown menu)[/td][/tr][tr][td]Renault[/td][/tr][tr][td]Ford[/td][/tr][/table][/td][td][table][tr][td]Column 1[/td][/tr][tr][td]10[/td][/tr][tr][td]20[/td][/tr][/table][/td][td][table][tr][td]Column 2[/td][/tr][tr][td]20[/td][/tr][tr][td]30[/td][/tr][/table][/td][td][table][tr][td]Column 3[/td][/tr][tr][td]20[/td][/tr][tr][td]20[/td][/tr][/table][/td][td][table][tr][td]Column 4[/td][/tr][tr][td]50[/td][/tr][tr][td]50[/td][/tr][/table][/td][/tr][/table]I really hope someone can help me with this thank you in advanceYogi bear Quote Link to comment Share on other sites More sharing options...
jggretton Posted January 21, 2007 Share Posted January 21, 2007 You could could store this information in hidden fields:[code=php:0]<input type="hidden" name="Ford_col1" value="20" >[/code]and access it via[code=php:0]<? $car = $_POST['car']; $col1 = $_POST[$car . '_col1'];?>[/code]But really, you shouldn't need to write the column info to the page at all. Keep it stored on the server so that when you recieve back the car you can then look it up.[code=php:0]<? $carInfo['Ford'] = array(20,30,20,50); $carInfo['Renault'] = array(10,20,20,50); $car = $_POST['car']; $col1 = $carInfo[$car][0]; $col2 = $carInfo[$car][1]; ...?>[/code] Quote Link to comment Share on other sites More sharing options...
yogibear Posted January 21, 2007 Author Share Posted January 21, 2007 hi thankyou hidden field what a good idea but i am having problem i can get it to display but not go in to the database this is my code i change col1 for col it didnt like col1 for some reason.[code]<?php$con = mysql_connect('localhost','***','***');if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("web22-james", $con); $car = $_POST['car']; $col = $_POST[$car .'_col'];$sql="INSERT INTO userinformation (col, car, first_name, last_name)VALUES('$_POST[col]','$_POST[car]','$_POST[firstname]','$_POST[lastname]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "$col";mysql_close($con)?>[/code]any ideas whats wrong many thanksyogibear Quote Link to comment Share on other sites More sharing options...
yogibear Posted January 21, 2007 Author Share Posted January 21, 2007 It works thank you for help now all i need to do is add another 4 textboxesmany thanksyogi Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.