inserting dynamic drop down menu data into mysql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm having a problem with a standard html form.  I'm using a php function to
populate a drop down menu on a standard form.  I want the contents of the
submitted form to insert into a mysql table. All of the variables are
inserted correctly except for the data from the drop down menu.  For some
reason it will only insert the first word in the variable.  It cuts off
everything after the frist word.  
 
Code:
 
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body bgcolor="#CCCC99">
<?
include("../includes/index.inc.php");
 
function build_dropdown() {
    $sql = "select category from categories ORDER BY category";
    $result = mysql_query($sql) or DIE(mysql_error()." - ".mysql_errno());
    
    while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        extract($row);
        $output .= "<option value=$category>$category</option>";
        }
    return $output;
    }
?>
<div align="center">
  <table width="600" border="0" cellpadding="0" cellspacing="0"
bgcolor="#FFFFFF">
    <tr>
      <td><img src="admin.jpg" width="600" height="185"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><form name="form1" enctype="multipart/form-data" method="post"
action="add_company_submit.php">
      <div align="center">
        <table width="99%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="22%"><font size="2" face="Georgia, Times New Roman,
Times, serif">Company Name</font></td>
              <td width="78%"><input name="name" type="text" id="name"></td>
            </tr>
            <tr>
              <td width="22%"><font size="2" face="Georgia, Times New Roman,
Times, serif">&nbsp;</font></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td width="22%">Company Category</td>
              <td><select name="category" type="text"><? echo
build_dropdown() ?>
              </select>
                </td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td><font size="2" face="Georgia, Times New Roman, Times,
serif">Phone Number</font></td>
              <td><input name="number1" type="text" id="number1"></td>
            </tr>
            <tr>
              <td><font size="2" face="Georgia, Times New Roman, Times,
serif">&nbsp;</font></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td><font size="2" face="Georgia, Times New Roman, Times,
serif">Toll Free Number</font></td>
              <td><input name="number2" type="text"></td>
            </tr>
            <tr>
              <td><font size="2" face="Georgia, Times New Roman, Times,
serif">&nbsp;</font></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td><font size="2" face="Georgia, Times New Roman, Times,
serif">Fax Number</font></td>
              <td><input name="fax" type="text"></td>
            </tr>
            <tr>
              <td><font size="2" face="Georgia, Times New Roman, Times,
serif">&nbsp;</font></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td><font size="2" face="Georgia, Times New Roman, Times,
serif">E-Mail Address</font></td>
              <td><input name="email" type="text"></td>
            </tr>
            <tr>
              <td><font size="2" face="Georgia, Times New Roman, Times,
serif">&nbsp;</font></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td><font size="2" face="Georgia, Times New Roman, Times,
serif">Website Address</font></td>
              <td><input name="web" type="text"></td>
            </tr>
            <tr>
              <td><font size="2" face="Georgia, Times New Roman, Times,
serif">&nbsp;</font></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td><font size="2" face="Georgia, Times New Roman, Times,
serif">Company Image</font></td>
              <td><input name="graphic" type="file">
                </td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><input type="submit" name="Submit" value="Submit">
                <input type="reset" name="Reset" value="Reset"></td>
            </tr>
        </table>
      </div>
      </form></td>
    </tr>
  </table>
</div>
</body>
</html>
 
----------------------------------------------------------------------------
--------------------------------------
 
Submit File
 
<?
$max_file_size = "5000000";
$input_error_string="";
$input_errors=0;
@$size = getimagesize ("$graphic");
 
if ($graphic_size >= $max_file_size)
{
  $input_errors++;
  $input_error_string = $input_error_string . $input_errors . ". File too
large<BR>";
}
if ($input_errors != 0) {
print "<center><font face=verdana size=2 color=666666>";
printf("%s\n",$input_error_string);
print "<a href=add_company.php><br>Click here to try
again</a></font></center>";
exit;
}
 
require("../includes/index.inc.php");
$sql_command="SELECT actname FROM businesses";
$db_recordset=mysql_query($sql_command);
$number=mysql_num_rows($db_recordset);
$i = 0;
$input_error_string="";
$input_errors=0;
WHILE ($i < $number):
 
$actpicname = mysql_result($db_recordset,$i,"actname");
 
$i++;  
ENDWHILE;
 
if ($input_errors != 0) 
{
print "<center><font face=verdana size=2 color=666666>";
printf("%s\n",$input_error_string);
print "<a href=add_company.php><br>Click here to try
again</a><font></center>";
exit;
}
 
mysql_query("INSERT INTO businesses
VALUES('','$name','$category','$number1','$number2','$fax','$email','$web','
$graphic_name')");
move_uploaded_file($graphic, "../dynamic/$graphic_name");
header("Location: business.php");
 
?>
 


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux