php - Calling a form through another form (button) -


i'm trying add db info through form called after pressing button part of form. more exactly, after pressing button, form printed, this:

<?php if(isset($_post['x'])) {     if(isset($_post['submit']))     {         $msg=mysqli_real_escape_string($_post['msg']);          mysqli_query($conn, "insert user_posts (msg) values ('$msg')");     } ?>     <form method="post">         <textarea name="msg" cols="100" rows="10"></textarea>         <input type="submit" name="submit" value="submit"/>     </form> <?php }   ?>     <form method="post">         <button type="submit" name="x">press this!</button>     </form> 

after press post['x'], form textarea appears intended, if press "post[submit]", page shows first button , can't figure why no info added db. don't see wrong logic... little guidance welcome! thank in advance!

when submit form, post data sent same page again, , since if statement add data database inside first if, won't sent.

first check if second form sent, if not check x button.

this solution:

<?php if(isset($_post['submit'])) {     $msg=mysqli_real_escape_string($_post['msg']);      mysqli_query($conn, "insert user_posts (msg) values ('$msg')"); } if(isset($_post['x'])) {     ?>     <form method="post">         <textarea name="msg" cols="100" rows="10"></textarea>         <input type="submit" name="submit" value="submit"/>     </form>     <?php } ?> <form method="post">     <button type="submit" name="x">press this!</button> </form> 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -