mysql - Can't get form posts to be stored in the database -


i can't figure out why posts form won't save in database.

this html:

<button type="button" class="write">write reviews</button> <form class="writeform"method="post"> <input type="text" required name="monicker" placeholder="name"> <textarea name="review" required maxlength="5000" placeholder="leave review here &#40;max 25,000 charachters&#41;"></textarea> <input type="submit" value="submit"> </form> 

and php:

<?php $dbc = mysqli::real_connect('localhost', 'user_name', 'not_password'); mysqli::select_db('db_name',$dbc); $monicker = mysqli::real_escape_string ($_post['monicker']); $review = mysqli::real_escape_string ($_post['review']); if(isset($_post['submit'])) {  $query = "insert reviews              (id, monicker, review, date)              values (default,'$monicker', '$review', 'curdate()');";     mysqli::query($dbc, $query); } mysqli::close(); ?> 

you didnt execute query : add line.

$result = $mysqli::query($query); 

i modified code, please check code :

  <?php             $dbc = mysql_connect('localhost', 'communi3_root', 'typeset');             mysql_select_db('communi3_cfds',$dbc);              $monicker = isset($_post['monicker']) ? mysql_real_escape_string ($_post['monicker']) : '';             $review = isset($_post['review']) ? mysql_real_escape_string ($_post['review']) : '';              if(isset($_post['submit'])){                 $current_date = date('y-m-d h:i:s');                 $query = "insert reviews (id, monicker, review, date) values (default,'$monicker', '$review', '$current_date');";                 $result = mysql_query($query)or die(mysql_error($dbc));             }             mysql_close();         ?> 

i found issues in previous code : 1. no checking on post variables. causes error because used directly without checking if set or not. 2. curdate() undefined function, use php date function instead.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -