Send a certain value ignore others

ok heres d full code

$query = "SELECT car_id,  car FROM " . $DBPrefix . "vechicle";
        $db->query($query, $params);
        $TPL_ride1_list = '<select name="ride1">' . "\n";
        while ($row = $db->fetch())
        {
            $selected = ($row['car_id'] . '' . $row['car'] == $ride1) ? 'selected="true"' : '';
            $TPL_ride1_list .= "\t" . '<option value="' . $row['car_id'] . '' . $row['car'] . '" ' . $selected . '>' .$row['car'] . '</option>' . "\n";
        }
        $TPL_ride1_list .= '</select>' . "\n";

In this line

$TPL_ride1_list .= "\t" . '<option value="' . $row['car_id'] . '' . $row['car'] . '" ' . $selected . '>' .$row['car'] . '</option>' . "\n";

you can see that you are still outputting both the ID and the car name as part of the value parameter.

yeah i can see that how do i go about it

Remove the field that you don’t want. Basically it needs to be as in post #19, where you said that’s what the code looks like now. You see, where it only has the one field inside the value parameter?

But this doesn’t equate to what you said back in post #19, where you said that it’s only showing the car ID, not the car name. I can’t see how this code would do that.

ok so the thiing is

this below shows

both car_id and car after selection…this shows car name in options

<option value="' . $row['car_id'] . '' . $row['car'] . '" ' . $selected . '>' .$row['car'] . '</option>

if submit i get both car_id and car in database dont want that

this below shows

only car_id after selection…this shows car name in options
i wont want that showing only id

'<option value="' . $row['car_id'] . '" '. $selected . '>' .$row['car'] . '</option>

hope u see what am going thru

Not really. The first code submits both the car_id and car to the database because you have both values inside the option value string. Remove the car field from there, and it will only submit the car_id field.

The second bit of code will use the car_id field for the value submitted with the form, but will use the car field to display to the user. Presuming that is what is in the car field, of course.

yes it will submit only the car_id field but since that shows up in the confirm page i mean but both car_id and car names are displayed if i remove car field it will only show car_id and submit that fine but it will only show car_id on the confirm page without showing the car name thus making it difficult for users to remember what they selected in the first place

I am confused now, and I wonder whether your templating system is causing some trouble. Is the code you posted in #21 the code for the confirm page, or for the initial selection page?

ok let me break it down

$query = "SELECT car_id,  car FROM " . $DBPrefix . "vechicle";
        $db->query($query, $params);
        $TPL_ride1_list = '<select name="ride1">' . "\n";
        while ($row = $db->fetch())
       
(this help remember what was selected if the user wants to make changes before confirming there choice)
 {
            $selected = ($row['car_id'] . '' . $row['car'] == $ride1) ? 'selected="true"' : '';


            $TPL_ride1_list .= "\t" . '

(this shows both the car_id and car which is also inside the value and both are submitted which i only want the car to display but car_id to submit this part is shown after the selection is made as it display only on the confirm page let call this page 2 or confirm page)

<option value="' . $row['car_id'] . '' . $row['car'] . '" ' . $selected . '>


(this shows on the first page selection page where the user select an option let call this page 1 )
' .$row['car'] . '</option>' . "\n";
        }
        $TPL_ride1_list .= '</select>' . "\n";

so in general it like this

page 1
shows car list
yoyota
benz
audi
lexus

page 2 or confirm page
shows your selection : 3 audi

which means “3 audi” get submitted to database, but if i remove ’ . $row[‘car_id’] . ’ from page 2

i get this displayed “audi” which means the name get submitted not the id i dont want that

if i remove ’ . $row[‘car_id’] . ’ from page 2

i get this displayed “3” which means the id get submitted i want that but the name wont be displayed for the user to remember that they selected audi instead they only see number 3

hope my explanation explains more thats how d code works

the moment you stop trying to sit on two chairs, or to work on two damned different scripts at once, your problem will be solved.
but given your stubbornness in listening to what you are told, i doubt it will ever happen.

There is no specific link between what gets displayed, and what gets submitted. What gets displayed is between the <option> and </option> tag, and what gets submitted is inside the value= parameter of the <option> tag.

I don’t understand this part - if you remove the car_id, then it only shows the id and not the name? This is the part I have trouble with.

Where? There’s nothing in the code you posted that would cause it to display the id and the car name, unless in the meantime you’ve updated the vechicles table to include that information. You can see yourself - it retrieves the id and the car name, and the only thing between the tags is the name.

This bit of code:

$selected = ($row['car_id'] . '' . $row['car'] == $ride1) ? 'selected="true"' : '';

means that it will only set the “selected” flag if you leave both the id and name in the option values. If you remove the name from the value, you’ll have to remove it from here too.

So, is the code you displayed above the code for the first page, or the second page? If it’s for both, how does it work differently? Your comments talk about which bits display on the first page and which display on the second, but there’s no code there to differentiate between the two pages - all I see is a check for $ride1 which is presumably extracted from a form variable elsewhere in the code, and used to set the selected flag.

its used to remember the selected option in case of a change being made before submitting

Sorry, I don’t understand this brief response. I know what the $selected is for, I was just pointing out that it relies on having both id and name in the submitted value, so when you remove the name you’ll have to edit that line, too.

oh yeah removing one wont make the code remember previously selected option, weird but that what is does

so now it looks like this

on dropdown menu it shows car names after selelction it shows the car selected id(car_id) without the name (sucks) i just want iit to show the car name also, but car id hidden which will be sent to dattabase.

$query = "SELECT car_id,  car FROM " . $DBPrefix . "vechicle";
        $db->query($query, $params);
        $TPL_ride1_list = '<select name="ride1">' . "\n";
        while ($row = $db->fetch())
        {
            $selected = ($row['car_id'] == $ride1) ? 'selected="true"' : '';
            $TPL_ride1_list .= "\t" . '<option value="' . $row['car_id'] . '" ' . $selected . '>' .$row['car'] . '</option>' . "\n";
        }
        $TPL_ride1_list .= '</select>' . "\n";

I can’t honestly see why the code above does not produce that output. It has just the car id inside the value parameter, and the car name between the option tags.

yeah, the thing is it works well for what it made for i just need a way to tweak it so that the car_id does or doesnt display but the car only get submitted

In your confirm code, are you querying the database to get the specific car information? Something like:

// confirm.php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $ride1 = (int)$_POST['ride1'];
    $query = "SELECT car_id,  car FROM " . $DBPrefix . "vechicle" . " WHERE car_id = " . $ride1;
    $db->query($query, $params);
    $car = $db->fetch();
    echo 'Selected car ' . $car['car'];
}

I think the basic issue is the meaning of the word “submit”.

I keep asking whether the code above is the original selection, or the confirmation code. I have the impression that it’s both, hence the creation of the $selected variable to show the selection. But that doesn’t explain why it seems to operate differently.

oh yeah sorry missed the question

its both