Hey guys,
I am having a problem with a PHP function (a dynamic dropdown box) and a form not inserting the data into my database. The db connection is fine and the dropdowns populate properly - here is the code.
Thanks for looking at it!
new_client.php
<?
include("head.php");
include("datacon.php");
include("function.php");
?>
<h2>Enter a New Client</h2>
<form method="post" action="insertp_client.php">
<table>
<tr height=30 valign=top>
<td align=right><b>Client Name :</b></td>
<td>
<input style="font-size:12px;color:#006699;font-family:verdana;background-color:#ffffff;" type="text" name="client_nameField">
</td>
</tr>
<tr height=30 valign=top>
<td align=right><b>Client Info :</b></td>
<td>
<textarea name="client_infoField" wrap="VIRTUAL" cols="50" rows="4"style="font-size:12px;color:#006699;font-family:verdana;background-color:#ffffff;"></textarea>
</td>
</tr>
<tr height=30 valign=top>
<td align=right><b>Country :</b></td>
<td>
<select name="country_idField" type="text" style="font-size:12px;color:#006699;font-family:verdana;background-color:#ffffff;">
<?
echo do_dropdown(p_country,country_id,country_name);
?>
</select>
</td>
</tr>
<tr height=30 valign=top>
<td align=right><b>City :</b></td>
<td>
<select name="city_idField" type="text" style="font-size:12px;color:#006699;font-family:verdana;background-color:#ffffff;">
<?
echo do_dropdown(p_city,city_id,city_name);
?>
</select>
</td>
</tr>
</table>
<input type=submit name=Submit value="Submit">
<input type=reset name=Submit2 value="Reset">
</form>
<?
include("foot.php");
?>
function.php
<?
function do_dropdown($table, $id, $name)
{
// Make a dropdown box
$query = "select $id, $name from $table order by $id";
$return = mysql_query($query) or die(mysql_error()." - ".mysql_errno());
while($row = mysql_fetch_array($return, MYSQL_ASSOC))
{
extract($row);
$output .= "<option value=".$row[$id].">".$row[$name]."</option>";
}
return $output;
}
?>
insertp_client.php
<?
include("head.php");
include("datacon.php");
include("function.php");
$client_name = $POST['client_nameField'];
$client_info = $POST['client_infoField'];
$country_id = $POST['country_idField'];
$city_id = $POST['city_idField'];
?>
<?
$query="insert into p_client (client_name,client_info,country_id,city_id) VALUES ('$client_name','$client_info','$country_id','$city_id')";
;
$result = MYSQL_QUERY($query);
?>
//Print Results
<H2>New Client Created !!</H2>
<table>
<tr height=30>
<td align=right><b>Client_name :</b></td>
<td><font color=blue><b><? echo $client name; ?></font></b></td>
</tr>
<tr height=30>
<td align=right><b>Client_info :</b></td>
<td><font color=blue><b><? echo $client info; ?></font></b></td>
</tr>
<tr height=30>
<td align=right><b>Country :</b></td>
<td><font color=blue><b><? echo $country_id; ?></font></b></td>
</tr>
<tr height=30>
<td align=right><b>City :</b></td>
<td><font color=blue><b><? echo $city_id; ?></font></b></td>
</tr>
</table><br><br>
Click <a href="index.php">here</a> to go back to Main Menu
<?
include("foot.php");
?>