Hi,
I'm very new to PHP and I wonder if anyone could help. I've created an online form which emails the results to me. It is all working fine apart from one field - a drop down menu of company names which gets its contents from a database (called tblCompanies). The field appears ok on screen, the company names are shown, but when the results are send in an email the company name (companyname) is replaced by the id number of the company (companyid).
The code for the drop down menu part of the form is here:
<select name="company" id="company" >
<option value="0">-- Select company from list --</option>
<?
// Select existing companies from the Companies table and populate option list
$query = "select * from tblCompanies GROUP by companyname order by companyname";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<option value=".$row["companyid"].">".$row["companyname"]."</option><br>";}
?>
</select>
and the line for emailing the selected company name is here:
$mesg .= "Company Applied to: $_POST[company]\n";
I would like it to be able to email the companyname to me, rather than the companyid, from the tblCompanies database.
Could anyone help me?
Many thanks for any help.
Rach
Pulling data from a database to be emailed via PHP form
Moderator: General Moderators
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
rach73,
dude uhm firstly i dont know if this is a typo thing but
secondly,
the reason why you get the "id" is because
the correct thing i believe would be
got it
Kendall
dude uhm firstly i dont know if this is a typo thing but
note the id and name attributes<option id="company" name="company" value="mysql entry">
secondly,
the reason why you get the "id" is because
WHAT DO YOU EXPECT...lolecho "<option value=".$row["companyid"].">
the correct thing i believe would be
Code: Select all
echo "<option value=".$row["companyname"].">".$row["companyname"]."</option><br>";Kendall
Easy 
You need to put the option values in quotes like this
Mark
You need to put the option values in quotes like this
Code: Select all
echo "<option value="".$row["companyname"]."">".$row["companyname"]."</option><br>";Change:
echo "<option value=".$row["companyname"].">".$row["companyname"]."</option><br>";
to:
echo '<option value="'.$row['companyname'].'">'.$row['companyname'].'</option><br>';
this will put quotes around the company name, without them you'll end up with value=foo bar .. and only foo will get posted, with the quotes you get "foo bar" and both will be posted.
Edit: Bech100 wins by a nose!
echo "<option value=".$row["companyname"].">".$row["companyname"]."</option><br>";
to:
echo '<option value="'.$row['companyname'].'">'.$row['companyname'].'</option><br>';
this will put quotes around the company name, without them you'll end up with value=foo bar .. and only foo will get posted, with the quotes you get "foo bar" and both will be posted.
Edit: Bech100 wins by a nose!