Click to See Complete Forum and Search --> : Results of a static dropdown


rbabich
07-08-2006, 10:17 AM
I am a newbie and have been struggling with passing the value of my html form in a static dropdown to a php query page that looks up the type of business in my database I am looking for.


The error I am getting is: Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/myservic/public_html/results.php on line 12 which is :

WHERE biztype = "'.$_POST['biztype'].'"'";

If there are any ideas, I would GREATLY appreciate it. Thanks!!!!



[code]
MY HTML FORM

<form action="results.php" method="post"><div align="right">
<div align="center"><br>
<select name="biztype">
<option selected>-select type--</option>
<option value="cleaning">cleaning</option>
<option value="electrical">electrical</option>
<option value="plumbing">plumbing</option>
<option value="heating_cooling">heating/cooling</option>
<option value="other">other</option>
</select>
<br>
<br>
<input name="Submit" type="Submit" >
</div>
</form>

-----
[MY PHP PAGE]

<?php

$db = mysql_connect("localhost","mylogin","password") or die("Problem connecting");

mysql_select_db("mydb") or die("Problem selecting database");

$sql = "SELECT * FROM contractor
WHERE biztype = "'.$_POST['biztype'].'"'";

$result = mysql_query($sql) or die ("Query failed");

//let's get the number of rows in our result so we can use it in a for loop

$numofrows = mysql_num_rows($result);

echo "<TABLE BORDER=\"1\">\n";
echo "<TR bgcolor=\"lightblue\"><TD>Company</TD><TD>Phone</TD><TD>Rating</TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result);
if($i % 2) {
echo "<TR bgcolor=\"yellow\">\n";
} else {
echo "<TR bgcolor=\"white\">\n";
}
echo "<TD>".$row['compname']."</TD><TD>".$row['phone']."</TD><TD>".$row['rating']."</TD>\n";
echo "</TR>\n";
}
echo "</TABLE>\n";
?>
[code]

Weedpacket
07-08-2006, 12:18 PM
Use [php]...[/php] tags around your PHP code when you post and mistakes like this will just scream at you. Viz:<?php

$db = mysql_connect("localhost","mylogin","password") or die("Problem connecting");

mysql_select_db("mydb") or die("Problem selecting database");

$sql = "SELECT * FROM contractor
WHERE biztype = "'.$_POST['biztype'].'"'";

$result = mysql_query($sql) or die ("Query failed");

//let's get the number of rows in our result so we can use it in a for loop

$numofrows = mysql_num_rows($result);

echo "<TABLE BORDER=\"1\">\n";
echo "<TR bgcolor=\"lightblue\"><TD>Company</TD><TD>Phone</TD><TD>Rating</TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result);
if($i % 2) {
echo "<TR bgcolor=\"yellow\">\n";
} else {
echo "<TR bgcolor=\"white\">\n";
}
echo "<TD>".$row['compname']."</TD><TD>".$row['phone']."</TD><TD>".$row['rating']."</TD>\n";
echo "</TR>\n";
}
echo "</TABLE>\n";
?>And you can see that you got confused with your quotes and double quotes on that line.

rbabich
07-08-2006, 12:42 PM
Thanks, Can you explain what the syntax should be. I used the quotes because I thought the result was to be determined.

dr bung
07-08-2006, 02:02 PM
$sql = "SELECT * FROM contractor WHERE biztype = '".$_POST['biztype']."'";