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 (max 25,000 charachters)"></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
Post a Comment