Dynamic Form Response
Posted: Fri Jan 21, 2011 12:27 am
I'm incredibly new to PHP and MySQL. I've started playing with creating a database of customers.
What I've got thus far is a very basic page that displays a customers first and last name taken from the database and displayed in a form list to select from. What I want to have happen is that when a customer's name is selected, their information such as address and contact information will display below. I've got an onClick command built into the code that currently displays a pop-up message and I'm thinking that there might be a way to use something similar to trigger their information to be displayed below.
Hopefully I've given a clear enough explanation. Thanks in advance for any help or guidance!
What I've got thus far is a very basic page that displays a customers first and last name taken from the database and displayed in a form list to select from. What I want to have happen is that when a customer's name is selected, their information such as address and contact information will display below. I've got an onClick command built into the code that currently displays a pop-up message and I'm thinking that there might be a way to use something similar to trigger their information to be displayed below.
Hopefully I've given a clear enough explanation. Thanks in advance for any help or guidance!
Code: Select all
<?php // formTest.php
require_once '../connections/login.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db($db_database, $db_server)
or die("Unable to select database: " . mysql_error());
$query = "SELECT * FROM customers ORDER BY last_name";
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
echo "Client<br /><SELECT NAME=customers SIZE=10 STYLE=width:175>";
while($nt=mysql_fetch_array($result))
{
echo <<<_END
<OPTION VALUE="$nt[cust_id]" onClick="alert('Hello, $nt[first_name] $nt[last_name]');">$nt[last_name], $nt[first_name]</OPTION>
_END;
}
echo "</SELECT>";
?>