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.

<?php
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);
}
};

<?php
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">
<?php echo(create_client_dropdown()); ?>
</select><br />

<label for="carrierno">Carrier</label>
<select id="carrierno" name="carrierno">
<?php 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 />

<?php $usernames = get_accountusername(); ?>

<label for="agentekpidno">Agentek PID Number (EIN#)</label>
<select id="agentekpidno" name="agentekpidno" onChange="get_name()">
<?php echo(create_agentekpidno_dropdown()); ?>
</select><br />

<label for="accountusername">Account User Name</label>
<select id="accountusername" name="accountusername" disabled=true>
<?php 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>
<?php
}

function echo_header()
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="validate.js"></script>
<?php 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">
<?php
}

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>
<?php
}

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;
}
?>

    Um...php tags? Please and thank you.

    What exactly is the problem? What's happening right now compared to what you want to be happening?

      Everything that is inbetween <? ?> is under php. When i select from the dropdown the page does not refresh and does not display the user name.

        sunking101 - go back and edit your first post. Put PHP tags around the code. It color-codes the code and makes it easier to read. I just learned to do this myself 🙂

          Thanks for the suggestion and i will do that from now on, but it doesn't seem like anything was highlighted.

            Honestly I gave up when I saw you echoing a PHP or JavaScript funtion, which I have never heard of or even tried (it would't work).

            <?// NOTE YOU should use <?php instead of short tags and your code is a comeplete mess if you want to use javascript with PHP then at least let the file know that is what you are doing!
            define('DB_NAME', '*****');
            define('DB_USER', '****');
            define('DB_PASSWORD', '****');
            define('DB_HOST', '****');
            define('ADMIN1', '*******');
            define('ADMIN1_EMAIL', '*****');
            
            $id_link = db_connection();
            echo_header();//what is this statement echoing a function?
            if($_POST["submit"])
            {
            echo("Thank you for your submission.<br />");
            $query = construct_query();
            $result = mysql_query($query);
            }
            else
            {
            echo_form();//same thing here why are you echoing a function you call one not echo it
            }
            echo_footer();
            mysql_close($id_link);
            
            function echo_js()
            {
            echo("<script type=\"text/javascript\">\r\n");
            ?>// What is this we are still in PHP because you are echoing it within the delimiters?
            // Only script specific to this form goes here.
            // General-purpose routines are in a separate file.
            function validateOnSubmit(thisform) {//this is JavaScript but not in Javascript
            with(thisform)//this too
            {
            var elem;//and this
            var errs=0;//what are you trying to do here either use JavaScript or PHP
            // 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');//more javascript
            if (errs==1) alert('There is a field which needs correction before sending');//more javascript
            
            return (errs==0);
            }
            };
            
            <?
            echo("</script>\r\n");//now you end what has never been started
            }
            
            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;
            }
            ?>
            ents<br/>\n";
              Write a Reply...