HTML/PHP:
<?php if(!empty($_GET['pID'])) $the_pID = mysql_real_escape_string($_GET['pID']);
开发者_Go百科 #echo $the_pID;
?>
<form action="inc/q/prof.php?pID=<?php echo $the_pID; ?>" method="post">
<select id="courseInfoDD" name="courseInfoDD" tabindex="1"><?php while($row3 = $sth3->fetch(PDO::FETCH_ASSOC)) {
echo "<input type='hidden' name='cID' value='$_POST['cID']'";
echo "<option><?php".$row3['prefix']." ".$row3['code']."</option>"; }echo "</select>"; ?>
<input type="text" id="addComment" name="addComment" tabindex="3" value="Enter comment" />
<input type="hidden" name="pID" value="<?php echo $the_pID; ?>">
<input type="submit" name="submit" id="submit" />
</form>
PHP/MYSQL
<?php // Get select box options
$pID3 = filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
$username = "###";
$password = "#####";
$pdo3 = new PDO('mysql:host=#####;dbname=####', $username, $password);
$pdo3->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth3 = $pdo3->prepare('
SELECT pID, C.cID, C.prefix, C.code
FROM Department D, Course C, Professor P
WHERE pID = ?
AND D.dID = C.dID
AND D.dID = P.dID;
');
$sth3->execute(array(
$pID3
));
?>
<?php
$connect = mysql_connect("#####", $username, $password) or die ("Error , check your server connection.");
mysql_select_db("####");
//Get data in local variable
if(!empty($_POST['addComment']))
$INFOO=mysql_real_escape_string($_POST['addComment']);
if(!empty($_POST['pID']))
$PIDD=mysql_real_escape_string($_POST['pID']);
if(!empty($_POST['courseInfoDD']))
$COURSEE=mysql_real_escape_string($_POST['courseInfoDD']);
#print_r($_POST);
echo $the_pID;
// check for null values
if (isset($_POST['submit'])) {
$query="INSERT INTO Comment (info, pID, CName) values('$INFOO','$PIDD','$COURSEE')";
mysql_query($query) or die(mysql_error());
echo "Your message has been received";
}
#else if(!isset($_POST['submit'])){echo "No blank entries";}
#else{echo "Error!";}
?>
I get the following error with the HTML/PHP above:Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
I feel like it deals with this line: echo <input type='hidden' name='cID' value='<?php echo '$_POST['cID']';?><option>".$row3['prefix']." ".$row3['code']."</option>"; }echo "</select>"; ?>
Does anyone see a problem here?
You can start with opening another PHP-tag after "option" ;-)
<?php echo '$_POST['cID']';?><option>".$row3['prefix']
Looks like you wanted to print option tag from PHP but left it outside later.
精彩评论