I have a html user entry form where 2 of the fields are drop-down boxes where the options come from data in the mysql database.
The first of these drop-downs is dependant on a query so a list of options is shown.
the second of these drop-downs will show only options based on the results of the user selection from the first drop-down.
The problem I am having that I have sussed out how to do this dependant drop-downs, but for this to work I need (I think!) a form action of action="<? $_SERVER['PHP_SELF'];?>"
to process the javascript code onChange="form.submit();" I am using to get result of the first drop down into the second.
BUT if I use this action, I cannot process the whole user entry form (ie. all the fields in the form) because the form keeps going back to itself instead of going to the process code I have in another .php file.
So if I use action "process_new_user.php" the form gets submitted / processed as soon as the user selects from the first drop down box, before they get to input any other data.
What I want to do is somehow get 2 dependant drop down boxes, plus a whole load of other user-entered data submitted from a form and insert the data into the mysql database.
I have put my code below
Any suggestions gratefully received
<?php
session_start ();
$_SESSION['username'] = $username;
require_once ('../mysql_connect.php');
$query = "SELECT CoName FROM tblClient, tblUser
WHERE tblUser.CLogin='$username'
AND tblUser.ConcesRef=tblClient.ConcesRef";
$result1 = mysql_query($query)
or die(mysql_error());
while($row1 = mysql_fetch_array($result1))
$CoName[] = $row1["CoName"];
?>
<form name="add_new_user" action="<? $_SERVER['PHP_SELF'];?>" method=post>
<p><b><font size="3" face="Arial, Helvetica, sans-serif">ADD NEW USER</font></b></p>
<table width="100%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td width="31%" height="32" valign="top">
<div align="right"><font face="Arial, Helvetica, sans-serif">Client:</font></div>
</td>
<td width="69%" valign="top">
<select name="client" onChange="form.submit();">
<option selected>choose client</option>
<?php
foreach($CoName as $value)
{
printf("<option>".$value."</option>");
}
?>
</select>
</td>
</tr>
<tr>
<td width="31%" height="48" valign="top">
<div align="right"><font face="Arial, Helvetica, sans-serif">Section Name:
</font></div>
</td>
<td width="69%" valign="top">
<?php
if (isset($_POST['client']))
{
// define section name
$Client = $_POST[client];
$query = "SELECT SectionName FROM tblSection, tblClient
WHERE tblClient.CoName='$Client'
AND tblSection.ClientRef=tblClient.ClientId";
$result2 = mysql_query($query)
or die(mysql_error());
while($row2 = mysql_fetch_array($result2))
$SectionName[] = $row2["SectionName"];
echo'<select name="section">
<option selected>choose section</option> ';
foreach($SectionName as $value)
{
printf("<option>".$value."</option>");
}
}
echo'</select>';
?>
<font face="Arial, Helvetica, sans-serif"> </font></td>
</tr>
<tr>
<td width="31%" valign="top">
<div align="right"><font face="Arial, Helvetica, sans-serif">Name:</font>
</div>
</td>
<td width="69%" valign="top"><font face="Arial, Helvetica, sans-serif">
<input type="text" name="new_name" size="40" maxlength="60">
</font> </td>
</tr>
<tr>
<td width="31%" valign="top">
<div align="right"><font face="Arial, Helvetica, sans-serif">Phone: </font></div>
</td>
<td width="69%" valign="top"><font face="Arial, Helvetica, sans-serif">
<input type="text" name="new_phone" size="40" maxlength="60">
</font></td>
</tr>
<tr>
<td width="31%" valign="top">
<div align="right"><font face="Arial, Helvetica, sans-serif">Fax: </font></div>
</td>
<td width="69%" valign="top"><font face="Arial, Helvetica, sans-serif">
<input type="text" name="new_fax" size="40" maxlength="60">
</font></td>
</tr>
<tr>
<td width="31%" valign="top">
<div align="right"><font face="Arial, Helvetica, sans-serif">E-Mail: </font></div>
</td>
<td width="69%" valign="top"><font face="Arial, Helvetica, sans-serif">
<input type="text" name="new_email" size="40" maxlength="60">
</font></td>
</tr>
<tr>
<td width="31%" height="59" valign="top">
<div align="right"><font face="Arial, Helvetica, sans-serif">System Username:</font></div>
</td>
<td width="69%" height="59" valign="top">
<p><font face="Arial, Helvetica, sans-serif">
<input type="text" name="new_username" size="40" maxlength="60">
<br>
</font><font face="Arial, Helvetica, sans-serif" size="2">Note - username
is first part of e-mail address, <br>
e.g. joe_bloggs@===.com would give a username of joe_bloggs</font></p>
</td>
</tr>
<tr>
<td width="31%" height="47" valign="top">
<div align="right"><font face="Arial, Helvetica, sans-serif">Password:</font></div>
</td>
<td width="69%" height="47" valign="top">
<p><font face="Arial, Helvetica, sans-serif">
<input type="password" name="new_password1" size="40" maxlength="40">
</font><font face="Arial, Helvetica, sans-serif" size="2"><br>
Passwords must be a minimum of 8 characters, <br>
and can contain letters and numbers</font></p>
</td>
</tr>
<tr>
<td width="31%" height="41" valign="top">
<div align="right"><font face="Arial, Helvetica, sans-serif">Re-Type Password:</font></div>
</td>
<td width="69%" height="41" valign="top"><font face="Arial, Helvetica, sans-serif">
<input type="password" name="new_password2" size="40" maxlength="40">
</font></td>
</tr>
</table>
<p align="center"><font face="Arial, Helvetica, sans-serif">
<input type="submit" name="Submit" value="Submit">
</font></p>
</form>