:eek: [FONT=Verdana]i need help with drop down menu and php. the problem is i am trying to have the code work so that whoever wishes to add to the options given in the drop down menu can by choose add new option. the page seems fine and doesn't give me any errors but it doesn't seem to be adding the new option in the drop down menu list. can anyone help!!![/FONT]
drop down menu and php
:eek: And just what does your code look like?!?!?!
~Brett
<?php
include("upalheader.inc");
$table = "RecType";
?>
<! -- *****************************************
start web page content
*****************************************-->
<table width='500' border="0" bgcolor="ffffff">
<tr>
<td align='center' valign='middle' nowrap>
<table cellpadding='10' cellspacing='2' border='0' style='border:1px solid #345487' class='row2'>
<tr>
<td width="253" valign="middle">
<div align="justify"><font color="#666666" size="2" face="Arial">
<b>Add Option Form</b></font></div></td>
</tr>
</table>
<br>
<?php
if ($Submit) {
$resultdupe = mysql_query("
SELECT *
FROM $table
WHERE rt_type='". $rt_type ."'
",$db);
$row = mysql_fetch_row($resultdupe);
if ($rt_type==$row[1]){
echo "Option \"$row[1]\" is already in use. Please try another.";
}
else {
$defaultrt_type=$rt_type;
// process form
$formdate =date("Y-m-d H:i:s");
$sql = "INSERT INTO RecType (
rt_type
)
VALUES (
'$rt_type'
)";
$result = mysql_query($sql);
echo "<br><br>";
echo "<br><br><font color='#666666' size='2' face='Arial'>";
echo "$formdate";
echo "<br><br>";
echo " $rt_type has sucessfully been added.\n";
echo "<br><br>";
$rt_type = Null;
// $password = Null;
// $userlevel = Null;
// echo "$rt_type";
echo "<form name=\"formaf\" method=\"post\" action=\"editrectype_input.php\"><div align=\"center\">
<input type=\"Submit\" name=\"Submit2\" value=\"Add New Option\">
</div></form>";
}
}
if (!$Submit || $error) {
echo $error;
// display form
?>
<table width='500' border="0" bgcolor="ffffff">
<tr>
<td align='center' valign='middle' nowrap>
<form name="formaf" method="post" action="editrectype_input.php">
<table cols="2" cellpadding='10' cellspacing='2' border='0' style='border:1px solid #345487' class='row2'>
<!-- <tr>
<td colspan="2" valign="middle">
<div align="justify"><font color="#666666" size="2" face="Arial">
<strong>*</strong>Required fields</font></div></td>
</tr> -->
<tr>
<td width="90"><strong><font color="#666666" size="2" face="Arial">
Add New Option</font><font color="#666666" size="2" face="Arial">:
</font></strong></td>
<td width="350"><strong><font color="#666666" size="2" face="Arial">
<input name="rt_type" type="text" id="rt_type"
value="<?php
echo $defaultrt_type;
?>"
size="35" maxlength="35"></font>
<font color=#ff0000>
<?php
echo $errorrt_type;
?>
</font></strong></td>
</tr>
</table>
<br>
<table width="69%" border="0" align="left">
<tr>
<td><div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
<td><div align="center">
<input type="reset" name="Submit2" value="Reset">
</div></td>
</tr>
</table>
</form></td>
</tr>
</table>
<?php
} // end if
?>
<! -- *****************************************
end the web page content
*****************************************-->
<?php
include("cmifooter.inc");
?>
[PHP] tags when you post code please... so much easier to read..... And strip the whitespace when you post your code too...
And are you seeing what I'm seeing?
name=\"Submit2\"
Yet you reference a posted variable "$Submit".... which is it? Submit2 or Submit?
~Brett
Sorry about that. Does this help?
<?php
include("upalheader.inc");
$table = "RecType";
?>
<table width='500' border="0" bgcolor="ffffff">
<tr>
<td align='center' valign='middle' nowrap>
<table cellpadding='10' cellspacing='2' border='0' style='border:1px solid #345487' class='row2'>
<tr>
<td width="253" valign="middle">
<div align="justify"><font color="#666666" size="2" face="Arial">
<b>Add Option Form</b></font></div></td>
</tr>
</table>
<br>
<?php
if ($Submit) {
$resultdupe = mysql_query("
SELECT *
FROM $table
WHERE rt_type='". $rt_type ."'
",$db);
$row = mysql_fetch_row($resultdupe);
if ($rt_type==$row[1]){
echo "Option \"$row[1]\" is already in use. Please try another.";
}
else {
$defaultrt_type=$rt_type;
// process form
$formdate =date("Y-m-d H:i:s");
$sql = "INSERT INTO RecType (
rt_type
)
VALUES (
'$rt_type'
)";
$result = mysql_query($sql);
echo "<br><br>";
echo "<br><br><font color='#666666' size='2' face='Arial'>";
echo "$formdate";
echo "<br><br>";
echo " $rt_type has sucessfully been added.\n";
echo "<br><br>";
$rt_type = Null;
// $password = Null;
// $userlevel = Null;
// echo "$rt_type";
echo "<form name=\"formaf\" method=\"post\" action=\"editrectype_input.php\"><div align=\"center\">
<input type=\"Submit\" name=\"Submit2\" value=\"Add New Option\">
</div></form>";
}
}
if (!$Submit || $error) {
echo $error;
// display form
?>
<table width='500' border="0" bgcolor="ffffff">
<tr>
<td align='center' valign='middle' nowrap>
<form name="formaf" method="post" action="editrectype_input.php">
<table cols="2" cellpadding='10' cellspacing='2' border='0' style='border:1px solid #345487' class='row2'>
<tr>
<td width="90"><strong><font color="#666666" size="2" face="Arial">
Add New Option</font><font color="#666666" size="2" face="Arial">:
</font></strong></td>
<td width="350"><strong><font color="#666666" size="2" face="Arial">
<input name="rt_type" type="text" id="rt_type"
value="<?php
echo $defaultrt_type;
?>"
size="35" maxlength="35"></font>
<font color=#ff0000>
<?php
echo $errorrt_type;
?>
</font></strong></td>
</tr>
</table>
<br>
<table width="69%" border="0" align="left">
<tr>
<td><div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
<td><div align="center">
<input type="reset" name="Submit2" value="Reset">
</div></td>
</tr>
</table>
</form></td>
</tr>
</table>
<?php
} // end if
?>
Yea I see...I'm sorry but I am new at this and I really have no past training in PHP or MySQL. My boss sort of just gave me this project to do and sort of just figure it out on my own. I am trying to understand how that all works when the variable is $Submit but then it's really not used like that anywhere else. Instead it's used just as Submit.
I just changed it but the drop down list still won't add the option. Am I being clear as to what I need help with here? Please let me know if I'm being unclear.
And what does this mean? I am assuming it's a SQL statement but can't seem to understand what it's role is in the code:
WHERE rt_type='". $rt_type ."'
Well, nothing does you better than reading up on mySQL queries in the mySQL manual and string concatenation in the PHP manual.
~Brett
where can i find all this information?
Thanks for the links. I was looking there but I guess I should start from the beginning and take it from there. Thanks.