Dynamic select menu

So, what I want to do it create a static drop down list with some persons name and I want it to do is
when a person’s name is selected I want it’s whole information from the database be visible.
For this I have:

  1. A database named ‘user_db’
  2. A table named ‘input_table’ on database ‘user_db’
  3. A simple form with select option named ‘select.php’
  4. A connection file named ‘select_connection.php’
  5. And a query file named ‘select_query.php’

Now what code I have made is:

  1. select.php
<form id="form1" name="form1" method="post" action="select_query.php">
List

<select name="select">
<option value="Asma">Asma</option>
<option value="Aasha">Aasha</option>
<option value="Raj">Raj</option>
<option value="Danial">Danial</option>
<option value="All">All</option>
</select>

<input type="submit" name="Submit" value="Submit" />

</form>
  1. select_connection.php

[php]

<?php $aa = mysql_connect("localhost","username","")… $ss= mysql_select_db("user_db"); ?>

[/php]

3.select_query.php
[php]

<? include('select_connection.php'); $sel = $_REQUEST['select']; $que = "SELECT * FROM input_table"; $sql= mysql_query($que); $d = mysql_fetch_array($sql); $x = $d['first_name']; if($sel==$x) $sel1 = "SELECT * FROM input_table WHERE first_name='$x'"; $que1 = mysql_query($sel1); else echo "Data not found"; ?>

[/php]

<table width="809" border="1">
<tr>
<td width="37">ID</td>
<td width="132">FIRST NAME </td>
<td width="158">LAST NAME </td>
<td width="109">SEX</td>
<td width="109">EMAIL</td>
<td width="109">PASSWORD</td>
<td width="109">COUNTRY</td>
</tr>

[php]

<?php while($row=mysql_fetch_array($que1)) { ?>

[/php]

<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['first_name']; ?></td>
<td><?php echo $row['last_name']; ?></td>
<td><?php echo $row['sex']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['password']; ?></td>
<td><?php echo $row['country']; ?></td>
</tr>

[php]

<?php } ?>

[/php]

</table>

Main Question: Now, when I execute my file select.php whose action is select_query.php
I get error saying:

  1. Notice: Undefined variable: que1 in C:\wamp\www\database\select_query.php on line 26
  2. Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\database\select_query.php on line 26

Kindly help with what and where I’m going wrong to display the required result.
Additionally: I’m using Dreamweaver 8 and Wamp server.

your query is failing

replace:
[php]
$que1 = mysql_query($sel1);
[/php]

with:
[php]
$que1 = mysql_query($sel1) or die(mysql_error());
[/php]

now you should get another error indicating why the query didnt suceed.
fix that error and boila!!!

I have already tried that but it still remains nonworking!

It still will not work i know, but now you you get a detailed error messge which shud help you figure it why is not working.

if it did gave u a different message error and dont know how to fix it post it here we will help

Sponsor our Newsletter | Privacy Policy | Terms of Service