开发者

HTML/PHP Survery not passing ID from table correctly

I'll try to keep it simple... this is the code I am using to populate a dropdown menu from a database. This populates the dropdown menu correctly.

<form action="formsubmit.php?team_id=6" 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 value=" . $temp['id'] . ">".htmlspecialchars($temp['lastn开发者_JS百科ame']) . ", " . htmlspecialchars($temp['firstname']) . "</option>";
            }
        ?>
    </select>
    <input type="submit" value="Submit!" />
</form>

What I'm attempting to do is pass the person's ID into along to the file formsubmit.php which is called on the submission of the form. When I use $die($sql) on my database query in formsubmit.php, the ID of the person is blank.... everything else gets passed through just fine. Here is the relevant code in formsubmit.php:

$quotetext = $_POST['quotetext'];
    $id = $_POST['id'];
    $team_id = $_GET['team_id'];
    $sql = "INSERT INTO quotes SET 
            speaker_id='$id',
            quotetext='$quotetext',
            game_id=2";
    die($sql);

EDIT: Fixed, credit to Michael.

<select name='name'>

Should be:

<select name='id'>


At first glance, it looks like a typo. Try:

$id = mysql_real_escape_string($_POST['name']);


In your form, you are using <select name='name'>, but in your PHP script you're calling for $_POST['id']. Change it to:

<select name='id'>


The problem is that you don't have a form variable with "id" as its name. It looks to me as you just need to change <select name='name'> to <select name='id'>.


$team_id = $_POST['name']

Your select element is named "name" and your form is "POST".


You need to change

$id = $_POST['id'];

to

$id = $_POST['name']; // as name is what you gave your select element
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜