Wednesday, 15 July 2015

html - How to use multiple forms to submit unique data PHP/MySQL -



html - How to use multiple forms to submit unique data PHP/MySQL -

the way i've structured form info creating them in while loop, each time created form take unique id. question is, how access them individually , update specified info mysql server. i've attempted in code @ end of script, i'm not sure how access forms individually

<?php include 'user_data.php'; include 'core.inc.php'; $query = mysql_query("select `post_text` `posts`,`sub_posts` sub_posts.post_id = posts.id , sub_posts.user_id='$user_id'"); while($row = mysql_fetch_array($query)){ ?><a href="#" class="askedclick"><?php echo $row[post_text].'<br>'?></a> <form action="<?php $curent_file ?>" method="post"> <textarea name="answer_field" > </textarea><br /> <input type="submit" value="submit answer"> <input type="hidden" name="post_id" value="<?php echo $row['post_id']; ?>" /> </form> <?php }//while loop if (isset($_post['answer_field']) && !empty($_post['answer_field'])){ $answer = mysql_real_escape_string($_post['answer_field']); $id = intval($_post ['post_id']); $query = "update `sub_posts` set `sub_answer`='$answer' `post_id`='$id'"; } ?>

only single form gets posted when clicking "submit" field. form name not submitted itself. instead, place post id form corresponds hidden field:

<input type="hidden" name="post_id" value="<?php echo $row['post_id']; ?>" />

and later:

$answer = mysql_real_escape_string ($_post ['answer']); $id = intval ($_post ['post_id']); $query = "update `sub_posts` set `sub_answer`='{$answer}' `post_id`={$id}";

note need escape reply before putting in query , create sure id number. otherwise, you're opening code sql injection attacks.

php html mysql sql forms

No comments:

Post a Comment