I have a database table that contains fields including category (cat) and posting price (postprice). I need to bind an input field on my web page to the postprice value corresponding to the category selected in the dropdown box on the same page. I'm seeing syntax error but am not sure what it is. Here's the code for the dropdown box:
<select name="postcat" class="req" style="width:220px" onchange="getCats(this.value);">
<?php
if ($_POST['postsubcats'] == "none") {
echo "<option value=\"none\" selected=\"selected\">Select a category</option>";
} else {
echo "<option value=\"none\">Select a category</option>";
}
?>
<?php
$querycat = "SELECT * FROM `index` LIMIT 0, 30 ";
$resultcat = mysql_query($querycat);
while($rowcat = mysql_fetch_array($resultcat)){
echo "<option value=\"" . $rowcat['cat'] . "\">" . $rowcat['title'] . "</option>\n";
}
?>
</select>
Here's the snippet for the input box:
<input type="text" id="adFee" name="adfee" contenteditable="false"
value="<?php SELECT 'postprice' FROM 'index' WHERE 'cat' = $_POST(['postcat']); ?>">
Thanks much for your help.
Edit Thanks to Mash, I've modified my code as follows:
<label>Posting Fee:</label><br/>
<?php
$queryprice = "SELECT 'postprice' FROM 'index' WHERE 'cat' = " . $_POST('postcat');
$resultprice = mysql_query($queryprice);
while($row= mysql_fetch_array($resultprice)){
echo '<input type="text" id="adFee" name="adfee" contenteditable="false" value="';
echo $row['postprice'] . '" />';
} ?>
I now receive Fatal Error: Function name must be a string. Am I missing a ' " or ; somewhere??
Fatal Error is resolved. New Error:
mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Revised Code:
<?php
$queryprice = "SELECT postprice FROM 'index' WHERE cat = '" . mysql_real_escape_string($_POST['postcat'])."'";
$resultprice = mysql_query($queryprice);
while($row= mysql_fetch_array($resultprice)){
?><input type="text" id="adFee" name="adfee" contenteditable="false" value="<?php echo $row['postprice'];?>">
<?php } ?>
Does this mean that my code block is not "seeing" the option field postcat?
(int)$_POST['postcat']or"'".mysql_real_escape_string($_POST['postcat'])."'"