/    Sign up×
Community /Pin to ProfileBookmark

Php dropdwon menu

<?php
//connecting to the database and running query

$dbc=mysqli_connect(‘localhost’,’root’,”,’sam_telephone’);
$get_list_sql=”SELECT id, CONCAT_WS(‘,’, l_name, f_name) AS display_name FROM
master_name;”;
$get_list_res= mysqli_query($dbc, $get_list_sql);
?>

<!–Building of drop down menu start from here–>

<form action=”post.php” method=”post”>
<select name=”sel_id”>
<option value=””>–Select One–</option>
<!–Starting while loop for fetching the array–>
<?php
while($x=mysqli_fetch_array($get_list_res,MYSQLI_BOTH)){
?>
<option value=”<?php $x[‘id’]?>” name=”<?php $x[‘id’]?>”><?php echo $x[‘display_name’]?></option>
<?php
}
?>
</select>
<input type=”submit” value=”submit”/>
</form>
<!–Till here every thing work fine–>

<?php

// this portion is not working what i want to do its to get the id, because if
//I can get the id, i can run the query and get the result which i want to get
// from this table
if(isset($_POST[‘sel_id’])){
$safe_id = mysqli_real_escape_string($mysqli, $_
POST[‘sel_id’]);
echo $safe_id;
}
?>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmNov 10.2013 — The default action of a form submission is GET, not POST. Add the action attribute to your form tag
Copy linkTweet thisAlerts:
@arifkuttyauthorNov 11.2013 — The default action of a form submission is GET, not POST. Add the action attribute to your form tag[/QUOTE]

Thanks for your help but i want to do it through, the reason is i am learning so want to learn how to do it through post.

I solved it i change the line

<option value="<?php $x['id']?>" name="<?php $x['id']?>"><?php echo $x['display_name']?></option>

TO

<option value="<?php echo $x['id']?>" ><?php echo $x['display_name']?></option>

means i add echo, to the value attribute, and deleted the name attribute,

Thanks
×

Success!

Help @arifkutty spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...