Hello everyone! I've just started learned to use mysql & php recently and am having problems with creating a php page that is also dynamic. The problem lies when I select an item from the drop down box, I need to use the selected item to query the database, refresh the page, and then return the result into a read only box. Any input would be of tremendous help. The area of focus would be when the agentekpidno is selected to use that to query the database again and return the accountusername.
<?
define('DB_NAME', '**');
define('DB_USER', '');
define('DB_PASSWORD', '');
define('DB_HOST', '');
define('ADMIN1', '***');
define('ADMIN1_EMAIL', '**');
$id_link = db_connection();
echo_header();
if($_POST["submit"])
{
echo("Thank you for your submission.<br />");
$query = construct_query();
$result = mysql_query($query);
}
else
{
echo_form();
}
echo_footer();
mysql_close($id_link);
function echo_js()
{
echo("<script type=\"text/javascript\">\r\n");
?>
// Only script specific to this form goes here.
// General-purpose routines are in a separate file.
function validateOnSubmit(thisform) {
with(thisform)
{
var elem;
var errs=0;
// execute all element validations in reverse order, so focus gets
// set to the first one in error.
//if(checkRequired('notes')) errs++;
if(checkRequired('agentekpidno')) errs++;
if(checkRequired('accountphoneno')) errs++;
if(checkRequired('carrierno')) errs++;
if(checkRequired('client')) errs++;
if (errs>1) alert('There are fields which need correction before sending');
if (errs==1) alert('There is a field which needs correction before sending');
return (errs==0);
}
};
<?
echo("</script>\r\n");
}
function echo_form()
{
?>
<noscript>
<p> Javascript is not currently enabled on your browser.
If you can enable it, your input will be checked as you
enter it (on most browsers, at least). You may find this
helpful.</p>
</noscript>
<script type=text/javascript language=javascript>
<!-- Hide Javascript on old browsers
function get_name(current)
{
username = current.options[current.selectedIndex].value
if (username != "")
{
form.logistics_activations.accountusername.disabled = false
}
else
{
form.logistics_activations.accountusername.disabled = true
}
}
-->
</script>
Add or update records in the activations table.<br /><br />
<form method="post" name="logistics_activations" onsubmit="return validateOnSubmit(this)" action="<? echo($_SERVER["PHP_SELF"]); ?>">
<form>
<input type="radio" name="add_update" value="Add"> Add
<br>
<input type="radio" name="add_update" value="Update"> Update
</form>
<label for="client">Client</label>
<select id="client" name="client">
<? echo(create_client_dropdown()); ?>
</select><br />
<label for="carrierno">Carrier</label>
<select id="carrierno" name="carrierno">
<? echo(create_carrier_dropdown()); ?>
</select><br />
<label for="accountphoneno">Account Phone Number (Ex. 678-393-1808)</label>
<input id="accountphoneno" name="accountphoneno" type="text" size="12" maxlength="12" value=""/><br />
<? $usernames = get_accountusername(); ?>
<label for="agentekpidno">Agentek PID Number (EIN#)</label>
<select id="agentekpidno" name="agentekpidno" onChange="get_name()">
<? echo(create_agentekpidno_dropdown()); ?>
</select><br />
<label for="accountusername">Account User Name</label>
<select id="accountusername" name="accountusername" disabled=true>
<? echo(display_accountusername()); ?>
</select><br />
<label style="width: 500px;" for="notes">Notes</label><br />
<textarea style="width: 500px;" id="notes" name="notes" rows="3" cols="50"></textarea><br />
<input style="float: right;" type="submit" name="submit" id="submit" value="submit" />
</form>
<?
}
function echo_header()
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="validate.js"></script>
<? echo_js(); ?>
<link rel="stylesheet" href="style.css" type="text/css">
<link href="CalendarControl.css" rel="stylesheet" type="text/css">
<title>Agentek Logistics Activations Form</title>
</head>
<body>
<script src="CalendarControl.js" language="javascript"></script>
<div id="header">Agentek Logistics Activations Form</div>
<div id="content">
<?
}
function echo_footer()
{
?>
</div>
<div id="footer">
<p>
<img src="images/html401.png"
alt="Valid HTML 4.01 Transitional" height="15" width="80" style="border: none; float: right;"><br />
<img src="images/css.png"
alt="Valid HTML 4.01 Transitional" height="15" width="80" style="border: none; float: right;">
</p>
</div>
</body>
</html>
<?
}
function construct_query()
{
$accountphoneno = $POST['accountphoneno'];
$client = $POST['client'];
$carrierno = $POST['carrierno'];
$agentekpidno = $POST['agentekpidno'];
$query = "insert into temp (accountphoneno, client, carrierno, agentekpidno) VALUES (
'$accountphoneno', '$client', '$carrierno', '$agentekpidno')";
$result = mysql_query($query);
/*
$retval = "INSERT INTO temp (accountphoneno, client, carrierno, agentekpidno) VALUES ('";
$retval .= $_POST["accountphoneno"] . "', '";
$retval .= $_POST["client"] . "', ";
$retval .= $_POST["carrierno"] . "', ";
$retval .= $_POST["agentekpidno"] . "', '";
return $retval;
*/
}
function create_client_dropdown()
{
$retval = "";
$retval .= "<option value=''></option>\r";
$query = "select distinct companyname from company order by companyname";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
{
$retval .= "<option value='" . $row[0] . "'>" . $row[0] . "</option>\r";
}
return $retval;
}
function create_carrier_dropdown()
{
$retval = "";
$retval .= "<option value=''></option>\r";
$query = "select distinct carriername from wancarrier order by carriername";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
{
$retval .= "<option value='" . $row[0] . "'>" . $row[0] . "</option>\r";
}
return $retval;
}
function create_agentekpidno_dropdown()
{
$retval = "";
$retval .= "<option value=''></option>\r";
$query = "select distinct einno from users order by einno";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
{
$retval .= "<option value='" . $row[0] . "'>" . $row[0] . "</option>\r";
}
return $retval;
}
function display_accountusername()
{
$agentekpidno = $_POST['agentekpidno'];
$retval = "";
$retval .= "<option value=''></option>\r";
$query = "select distinct accountusername from activations where agentekpidno = '$agentekpidno'";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
{
$retval .= "<option value='" . $row[0] . "'>" . $row[0] . "</option>\r";
}
return $retval;
}
function get_accountusername()
{
$retval = "";
$retval .= "<option value=''></option>\r";
$query = "select distinct accountusername from activations";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
{
$retval .= "<option value='" . $row[0] . "'>" . $row[0] . "</option>\r";
}
return $retval;
}
function db_connection()
{
$server = DB_HOST;
$loginsql = DB_USER;
$passsql = DB_PASSWORD;
$dbname = DB_NAME;
$connect = mysql_connect($server, $loginsql, $passsql);
$db = mysql_select_db($dbname, $connect);
if (!$connect || !$db)
die("Connection Failed!");
return $connect;
}
?>