Hi everyone,

I have pulled data from mysql into an select list in my admin area.

$query="SELECT id, linklabel FROM pages ORDER BY id ASC";
[I]//I am not sure if the form should be like this...?[/I]
'<form name=test id=test  action=edit_page.php method=post>';
$result = mysqli_query ($myConnection, $query);
echo "<select class=\"boxstyles\" name=linklabel=''>Choose a page to edit</option>";
[I]// printing the list box select command[/I]

while($nt=mysqli_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[linklabel]</option>";
[I]// Option values are added by looping through the array[/I] 
echo "</select>";// Closing of list box 

So..now the values are inside the listbox, and the next thing I want to do is, when a value is clicked, I want to redirect to an edit_page.php, where I have a form for editing the page.

The form should be prepopulated with the current text and information in the different form fields.

I am just not sure how to grab the selected value from the select box, and the relevant information from the chosen value in the list box, and display it in the form fields in: edit_page.php

I am at a learning stage, so I hope you will bear with me, if this is a silly question :-)

Looking forward to hearing from some of you!


0) Your select box has several HTML errors: name=linklabel='' should probably read name='linklabel' Put quotes around all attribute values in HTML.
1) Use the onclick event in JavaScript: <select onclick='document.test.submit()'...> or something like that - I don't know the necessary javascript by heart.
2) In edit_page.php you get the selected value of your list box as a post variable: $selected = $_POST['linklabel']; // now $selected contains the id of the selected option

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.