I am trying to do a small poll that fills a selection for a drop down menu from a list of names from a database. The survey does it right. I want to submit a quote that the user sends with this name to the quotation database. The text of the quote that they enter in the field is correct, however, the name selected from the menu is not transmitted. Instead, I get an empty name field.
I understand that part of my code is out of context, but the name is the only thing that doesn't get it properly.
In the submit form, I include a php file that passes this data to the database:
<form action="<?php $name = $_POST['name']; include "formsubmit.php";?>" method="post">
<label> <br />What did they say?: <br />
<textarea name="quotetext" rows="10" cols="26"></textarea></label>
<input type="submit" value="Submit!" />
</form>
From this, the $ name variable is called (which fills my drop-down menu):
echo "<select name='name'>";
while ($temp = mysql_fetch_assoc($query)) {
echo "<option>".htmlspecialchars($temp['name'])."</option>";
}
echo "</select>";
And here is my formubmit.php:
<?php:
mysql_select_db('quotes');
if (isset($_POST['quotetext'])) {
$quotetext = $_POST['quotetext'];
$ident = 'yankees';
$sql = "INSERT INTO quote SET
quotetext='$quotetext',
nametext='$name',
ident='$ident',
quotedate=CURDATE()";
header("Location: quotes.php");
if (@mysql_query($sql)) {
} else {
echo '<p> Error adding quote: ' .
mysql_error() . '</p>';
}
}
?>
source
share