html - Error when trying to insert a comment on a blog post php -
i trying insert comments on blog post , keep getting error message. don't know if database set correctly, or if i'm missing syntax error. have form page , handle page. form:
<h1><center> add comment form</center></h1> <form action="hc.php" method="post"> <fieldset> <h3>post comment.</h3> <br> <textarea name="comment"cols="50"rows="10"id="comment" > </textarea><br> <input type="hidden" name="comid" value="'.$comid .'"/> <input type="hidden" name="blogid" value="'.$blogid .'"/> <input type="submit"value="submit"name="submit" /> <input type="reset"value="clear"> </fieldset> </form>
my handle page following:
<?php include ('./includes/mysqli_connect.php'); $blogid = $_session['blogid']; $comment = $_session['comment']; $comdate = $_session['comdate']; $comid = $_session['comid']; $userid = $_session['userid']; //if (isset($_get['blogid']) && isset($_get['userid']) && isset($_get['comment'])){ $query = "insert comments(comid, blogid, userid, comment, comdate) values ('$comid', '$blogid','$userid','$comment','$comdate')"; $result= @mysqli_query($dbc,$query); $comid=null; $blogid=null; $userid=null; if ($results) { echo "thank information has been submitted."; } else { echo "there error! " . mysqli_error($dbc); } ?>
i new @ php , appreciate help.
the error message is:
there error! cannot add or update child row: foreign key constraint fails (
codecrew_users
.comments
, constraintcomments_ibfk_1
foreign key (blogid
) referencesblog
(blogid
))
$query = "insert comments(comid, blogid, userid, comment, comdate) values ('$comid', '$blogid','$userid','$comment','$comdate')";
so... table comments
has field on requires foreign key.
i'm not sure value causing error 1 of values not match id in table.
so 1 of these has invalid value:
'$comid', '$blogid','$userid','$comment','$comdate'
Comments
Post a Comment