Database > MySQL database
Dynamic select menu
(1/1)
ave_pie:
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
--- Code: ---<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>
--- End code ---
2. select_connection.php
--- PHP Code: ---
<?php
$aa = mysql_connect("localhost","username","")…
$ss= mysql_select_db("user_db");
?>
--- End code ---
3.select_query.php
--- PHP Code: ---
<?
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";
?>
--- End code ---
--- Code: ---<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>
--- End code ---
--- PHP Code: ---
<?php
while($row=mysql_fetch_array($que1))
{
?>
--- End code ---
--- Code: ---<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>
--- End code ---
--- PHP Code: ---
<?php
}
?>
--- End code ---
--- Code: ---</table>
--- End code ---
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.
wilson382:
your query is failing
replace:
--- PHP Code: ---
$que1 = mysql_query($sel1);
--- End code ---
with:
--- PHP Code: ---
$que1 = mysql_query($sel1) or die(mysql_error());
--- End code ---
now you should get another error indicating why the query didnt suceed.
fix that error and boila!!!!
ave_pie:
I have already tried that but it still remains nonworking!
wilson382:
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
Navigation
[0] Message Index
Go to full version