 |
 |
PHP/MySQL: Combobox not sending data
|
 |
|
 |
|
Grizzled Veteran
Join Date: Aug 2002
Location: Cardboard Box
Status:
Offline
|
|
Okay I am pulling data from another table to use as input on a form field:
<?php
$sql="SELECT id, vendorname FROM vendors";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["id"];
$vendorname=$row["vendorname"];
$options.="<OPTION VALUE=\"$id\">".$vendorname.'</option>';
}
?>
<select name=vendorname>
<option value=0>Select
<?=$options?>
</select>
It pulls the data from the column in the other table fine, but after submitting the form, I get nothing in that field. I could use a fresh set of eyes, since mine are a little blurred from staring at text for 2 hours. Am I missing something obvious? Any suggestions would be appreciated!
Here is the form in it's entirety:
<?php
include('general/header.inc');
require_once('general/general.php');
if (!(isset($_POST['SubmitForm_x'])))
{ ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Insert into inventory</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<link href="style/style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="scripts/pdw.js"></script>
<script type="text/javascript">
function checkForm(){
formErrors = new Array();
isValidAny(document.getElementById('lotnumber_ID') , 'Lot Number:: ', true);
isValidAny(document.getElementById('expdate_ID'), 'Exp Date:: ', true);
isValidAny(document.getElementById('description_ID '), 'Description:: ', true);
isValidAny(document.getElementById('vendor_ID'), 'Vendor:: ', true);
isValidAny(document.getElementById('receivedate_ID '), 'Receive Date:: ', true);
isValidAny(document.getElementById('receivetemp_ID '), 'Receive Temp (C):: null', true);
isValidAny(document.getElementById('storagetemp_ID '), 'Storage Temp: (C):: null', true);
isValidAny(document.getElementById('receivedby_ID' ), 'Received by:: null', true);
isValidAny(document.getElementById('instructionsat tached_ID'), 'Instructions Attached:: null', true);
isValidAny(document.getElementById('packageintegri ty_ID'), 'Package Integrity:: null', true);
isValidAny(document.getElementById('acceptable_ID' ), 'Acceptable:: null', true);
isValidAny(document.getElementById('deliverymethod _ID'), 'Delivery Method:: null', true);
isValidAny(document.getElementById('notes_ID'), 'Notes:: null', true);
var errorText = '';
if (formErrors.length > 0){
for (var i=0; i<formErrors.length; i++)
errorText = errorText + formErrors[i] + '\n';
alert(errorText);
return false;
}
return true;
}
</script>
</head>
<body>
<form name="InsertForm" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" onSubmit="return checkForm()">
<div id="insertblock">
<table>
<tr><td class="tableheader" colspan=2>Insert into inventory</td></tr>
<tr>
<th>Lot Number:</th>
<td><input type=TEXT name="lotnumber" id="lotnumber_ID" size=30 maxlength=100 value=""/></td>
</tr>
<tr>
<th>Exp Date:</th>
<td><input type=TEXT name="expdate" id="expdate_ID" size=10 maxlength=10 value=""/></td>
</tr>
<tr>
<th>Description:</th>
<td><input type=TEXT name="description" id="description_ID" size=30 maxlength=100 value=""/></td>
</tr>
<tr>
<th>Vendor:</th>
<td>
<?php
$sql="SELECT id, vendorname FROM vendors";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["id"];
$vendorname=$row["vendorname"];
$options.="<OPTION VALUE=\"$id\">".$vendorname.'</option>';
}
?>
<select name=patientssn>
<option value=0>Select
<?=$options?>
</select>
</td>
</tr>
<tr>
<th>Receive Date:</th>
<td><input type=TEXT name="receivedate" id="receivedate_ID" size=10 maxlength=10 value=""/></td>
</tr>
<tr>
<th>Receive Temp (C):</th>
<td><input type=TEXT name="receivetemp" id="receivetemp_ID" size=4 maxlength=4 value=""/></td>
</tr>
<tr>
<th>Storage Temp: (C):</th>
<td><input type=TEXT name="storagetemp" id="storagetemp_ID" size=4 maxlength=4 value=""/></td>
</tr>
<tr>
<th>Received by:</th>
<td><input type=TEXT name="receivedby" id="receivedby_ID" size=30 maxlength=100 value=""/></td>
</tr>
<tr>
<th>Instructions Attached:</th>
<td><select name="instructionsattached" id="instructionsattached_ID"><option value="">-<option value="Yes">Yes</select></td>
</tr>
<tr>
<th>Package Integrity:</th>
<td><select name="packageintegrity" id="packageintegrity_ID"><option value="null">-<option value="Intact">Intact<option value="Compromised">Compromised</select></td>
</tr>
<tr>
<th>Acceptable:</th>
<td><select name="acceptable" id="acceptable_ID"><option value="null">-<option value="Yes">Yes</select></td>
</tr>
<tr>
<th>Delivery Method:</th>
<td><select name="deliverymethod" id="deliverymethod_ID"><option value="null">-<option value="FedEx">FedEx<option value="Courier">Courier<option value="UPS">UPS<option value="DHL">DHL<option value="USPS">USPS</select></td>
</tr>
<tr>
<th>Notes:</th>
<td><input type=TEXT name="notes" id="notes_ID" size=30 maxlength=100 value=""/></td>
</tr>
<tr>
<td class="tablefooter" colspan="2"><a href="javascript:history.back()"><img src="style/back.gif" alt="Back"/></a>
<input type="image" src="style/insert.gif" name="SubmitForm" alt="Insert"/></td>
</tr>
</table>
</div>
</form>
</body>
</html>
<?php } else {
$insertSql = "INSERT INTO inventory (
lotnumber
,expdate
,description
,vendor
,receivedate
,receivetemp
,storagetemp
,receivedby
,instructionsattached
,packageintegrity
,acceptable
,deliverymethod
,notes
) VALUES ( "
." '".addslashes($_POST['lotnumber'])."'"
.", '".addslashes($_POST['expdate'])."'"
.", '".addslashes($_POST['description'])."'"
.", '".addslashes($_POST['vendor'])."'"
.", '".addslashes($_POST['receivedate'])."'"
.", '".addslashes($_POST['receivetemp'])."'"
.", '".addslashes($_POST['storagetemp'])."'"
.", '".addslashes($_POST['receivedby'])."'"
.", '".addslashes($_POST['instructionsattached'])."'"
.", '".addslashes($_POST['packageintegrity'])."'"
.", '".addslashes($_POST['acceptable'])."'"
.", '".addslashes($_POST['deliverymethod'])."'"
.", '".addslashes($_POST['notes'])."'"
.")";
$MyDb->f_ExecuteSql($insertSql);
header('Location: list.php');
}
?>
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
What other table? What field is not being passed on to your form processing? Could you please be more specific?
Looking at your code, this looks problematic:
<select name=vendorname>
<option value=0>Select
<?=$options?>
</select>
Where is your </option> tag? Where is your print statement? I've personally not seen the equal sign being used as a print statement.
I would do this:
<select name = "vendor">
<option value = "">Select</option>
<?php print $options; ?>
</select>
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Aug 2002
Location: Cardboard Box
Status:
Offline
|
|
It is pulling from table "vendors" the field "vendorname" from the same database. A </option> tag would help huh? I'm a PHP newbie, but I still should have caught that. I used your suggestion, and after making a selection and submitting it, it records the row id instead of the "vendorname" field. And this:
<select name = "vendorname">
<option value = "">Select</option>
<?php print $options; ?>
</select>
Gets me nothing at all. I'm confused as to why "vendor" would at least record something and "vendorname" would not, since the field is in fact called "vendorname." With few exceptions I am doing much better with learning all this btw. Thanks for helping (this time and last).
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
The form <?=expression?> is equivalent to <?php echo expression; ?>. Your PHP has to by set up to accept that syntax, but it normally just throws an error if it isn't, so that shouldn't be the problem.
I can't see anything in the code that looks wrong, so I'd double-check the basic assumptions: Are you connected to the right database to get the data at that time? Do you have the right columns? Is the table actually populated? By the by, it will be the row id that gets passed as POST data, because that's what's in the value option is set to.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Aug 2002
Location: Cardboard Box
Status:
Offline
|
|
Originally Posted by Chuckit
Are you connected to the right database to get the data at that time?
Yes, it is all in the same database and everything else is connecting fine.
Originally Posted by Chuckit
Do you have the right columns?
I have checked a dozen times and the column is indeed called "vendorname".
Originally Posted by Chuckit
Is the table actually populated?
With one row. Otherwise the combo box would not give me anything to select, and it does.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Aug 2002
Location: Cardboard Box
Status:
Offline
|
|
Originally Posted by Chuckit
By the by, it will be the row id that gets passed as POST data, because that's what's in the value option is set to.
Oops. 
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Aug 2002
Location: Cardboard Box
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
I'm confused... The problem was that the ID was being posted rather than the value, and you wanted the value? I thought you were getting nothing?
You probably do want to add that </option> tag there. I remembered after my post that it is not required since the next <option> will force a new option, but you should probably put it in there anyway.
Chuckit: wasn't hip to using the equals sign that way... Thanks for the lesson! Is there a name for this form of syntax?
Edit: just read GreenG4's response to my first post here, disregard all of this... I'm also a little slow right now having worked on my own programming for several hours tonight 
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Originally Posted by besson3c
Chuckit: wasn't hip to using the equals sign that way... Thanks for the lesson! Is there a name for this form of syntax?
The PHP option that enables it is short_open_tags (which allows both <? ?> and <?= ?> in addition to the normal <?php ?>), so I think it's generally called the short equals tag or something like that.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Aug 2002
Location: Cardboard Box
Status:
Offline
|
|
Sorry for the confusion. At first I was getting nothing and then just got the id. Two problems, I guess. Thanks again to both of you!
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|