php - html form inputs are not saved in MySQL -
i have username/password <form>
, if false, display invalid users, if true display <textarea>
, users can comment submit.
basically, code below, then
statement if login correct then..
session_start(); $_session['name'] = $name; echo "success, hi $name"; echo "<table> <tr><td>insert comment here</td><td>poster</td> <tr><td><form action='post.php' method='post'><textarea name='content'></textarea> </td> <td> $name</td> </tr> <input type='submit' name='submit' value='submit'> </form> </table>";
in relation <form>
above, created post.php parse data coming <form>
, insert database.
<?php mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db("data") or die (mysql_error()); ?> <?php if (isset($_post['submit'])) { $cont = $_post['content']; //data coming index.php <form> mysql_query("insert data ('content') values ('$cont')"); } else { } ?>
what baffles me, there no errors being shown. when input on <textarea>
clicked submit, goes localhost/post.php when refresh index page, submitted data not saved/recorded database.
it looks few things wrong code above. please refer link on connecting , showing sql related issues
your sql invalid, not inserting "$cont" table, looks trying insert database name "data". check out link more info on sql insert
also few things have above:
- i avoid using word "data" database name.
- make sure not opening sql injection.
Comments
Post a Comment