开发者

textarea post into mysql not working

I have a textarea in a form that im trying to POST into a mysql database. However, when i insert the values, i get about 5 lines in the database. 4 of them have no information or minimal information and one of the lines is how i want it. How can i get rid of the other four lines? thanks.

EDIT: actually none of the lines have all the right info in the right spots and i have double checked the inset statement to make sure everything lines up.

the code:

<form method='POST' action="index.php">
<textarea id ='answerbox' autocomplete='off' cols="80" rows="5" name='answer'></textarea>
<input type='submit' value='submit'>

<?php
    include 'connect.php';
    $date=date("Y-m-d");
    $time=time();
     开发者_Python百科       $answer=['answer'];
    $user=$_SESSION['username'];
    $id=$_GET['id'];
    $put=mysql_query("INSERT INTO solutions VALUES ('','0','$date','$time','$user', '$answer')");
    ?>


Try:

<?php
    if($_POST['answer'] != '')
    {
       include 'connect.php';
       $date=date("Y-m-d");
       $time=time();

       $answer= $_POST['answer'];
       $user=$_SESSION['username'];
       $id=$_GET['id'];
       $put=mysql_query("INSERT INTO solutions VALUES ('','0','$date','$time','$user', '$answer')");
    }
    ?>


Your textarea is named as "answer" while its ID is "answerbox". You should be able to retrieve its value through $_POST['answer'];

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜