Jump to content

inserting information using a dropdown menu


yogibear

Recommended Posts

Hi all

I 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 advance

Yogi bear
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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 thanks
yogibear
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.