Jump to content

Reading from previous page drop down list


ashrobbins87

Recommended Posts

Hi I'm having real trouble with this, and it should be such a basic thing. I have a drop down list on one page which reads values from my DB and lets the user choose one, this works fine. However I can't work out how to pass the option they have chosen to the next page, so that the values corresponding to their choice can be put into fields. Here is the code from the sending page, this is where I think the problem is, because when I try to echo $_POST["users"]; (the name of the <select>) on the next page, all it says it "Array".

<form method="POST" action="../user.php"  >
<select name="users[]">
<?php
$mysqli = mysqli_connect("localhost","root","pass","opp_group");
//Get list of users in drop down

$getUsers_sql ="SELECT id, firstname, surname FROM cms_users ORDER BY firstname";
$getUsers_res = mysqli_query($mysqli, $getUsers_sql)or die(mysqli_error()); 


while ($row = mysqli_fetch_assoc($getUsers_res)) 
{ 

    echo '<option value="' . $row['id'] . '">' . $row['firstname'] . ' ' . $row['surname'] . '</option>'; 
$f = $row['firstname'];
$s = $row['surname'];
} 
echo "</select>
<a href=\"javascript:eventWindow('../user.php?f=".$f."&s=".$s."');\">
<input type=\"submit\" name=\"viewuser\" value=\"View\" />
</a>";

?>
</form>

 

 

Well at the moment I'm just trying to echo the value to makes sure it receives it correctly. But i eventually want it in a table.

 

This is user.php at the moment...

<?php

echo "".$_POST["users"]."";


echo "
<table>
<tr>
<td><input type=\"submit\" name=\"update\" value=\"Update User\"></td>
<td><a href=\"javascript:eventWindow('cms/deletevalidation.php');\"><input type=\"submit\" name=\"delete\" value=\"Delete\"></a></td>
</tr>
</table>
<br/><br/>

<table>
<tr><td>First Name: </td><td><input type=\"text\" name=\"firstname\" size=\"20\">".$f."</input></tr>
<tr><td>Surname: </td><td><input type=\"text\" name=\"surname\" size=\"20\" >".$s."</input></tr>
<tr><td>Username: </td><td><input type=\"text\" name=\"username\" size=\"20\"></tr>
<tr><td>Password: </td><td><input type=\"text\" name=\"password\" size=\"20\"></tr>

</table>";

?>

The snippet of javascript in there is to do with a separate function and not related to this.

 

That's because it's an array :)

 

I think using the [] in the name makes it an array, do you want them to pick multiple names?

 

your code..

<select name="users[]">

 

If you are just picking one name then maybe just put it like this

<select name="users">

 

Or you could just echo out the one result from the array like this

 

<?php
       $nameArray = $_POST['users'];
       echo $nameArray[0];
?>

 

 

hope this helps in some way

 

Stephen

Yeah, I know its because its an array, the book I'm using said to use the [] because I could be sending any of the options, and apparently it lets the user choose the option they want?? Am I missing something here? Sure the code from the initial page to post something is

<form method="POST" action="../user.php" >

<select name= "users" >

 

and to receive it on the next page its just

 

echo $_POST["users"];

Ok this is sort of solved now, managed to muddle a solution somehow!

 

The problem now is that it populates the fields if I open the user.php page in the same browser window, but not when I open it in the javascript popup.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.