HTML / PHP poll is not passed to MySQL database properly

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>';
    } 
    }
?>
+3
source share
2

, , , , , , $name = $_POST ['name'], $quotetext = $_POST [ quotetext ']. sql, .

, , , ( , , , $query ):

1:

<form action="formsubmit.php" method="post">
    <label> <br />What did they say?: <br />
    <textarea name="quotetext" rows="10" cols="26"></textarea></label>
    <select name='name'>
    <?php
    while ($temp = mysql_fetch_assoc($query)) {
        echo "<option>".htmlspecialchars($temp['name'])."</option>";
    }
    ?>
    </select>
    <input type="submit" value="Submit!" />
</form>

formsubmit.php:

<?php
    mysql_select_db('quotes');
    if (isset($_POST['quotetext'])) {
        $quotetext = $_POST['quotetext'];
        $name = $_POST['name'];
        $ident = 'yankees';
        $sql = "INSERT INTO quote SET 
                quotetext='$quotetext',
                nametext='$name',
                ident='$ident',
                quotedate=CURDATE()";
        if (@mysql_query($sql)) {
            header("Location: quotes.php");
        } else {
            echo '<p> Error adding quote: ' . 
                mysql_error() . '</p>';
        } 
    }
?>
+2
echo "<select name='name'>";

    while ($temp = mysql_fetch_assoc($query)) {
     $nyme = htmlspecialchars($temp['name']);
    echo "<option value='$nyme'>$nyme</option>";
    }                       
echo "</select>";-

$_POST

$_POST, , script.

$name = $_POST['name'];

<form action='formsubmit.php' .....>

whereever.php. , .

if (@mysql_query($sql)) {
          header("Location: quotes.php");

} else {
    echo '<p> Error adding quote: ' . 
        mysql_error() . '</p>';
} 
+1

All Articles