justlukeyou Posted May 26, 2012 Share Posted May 26, 2012 Hi, I have code which contains and submits only 'question' to the 'question' column from a form. However, I am struggling to add a second input called 'comments' into the 'comments' column. Does anyone know how to do this please? <?php if(isset($_POST['form_id'])){ $question = mysql_real_escape_string(trim($_POST['question'])); $comments = mysql_real_escape_string(trim($_POST['comments'])); $error = false; if(!isset($question) || empty($question)) { $error = "Please enter a question."; } if(preg_match("/[a-zA-Z0-9]{1,}$/", $question) == 0 && !$error) { $error = "The question you entered must contain only letters or numbers."; } if(preg_match("/[a-zA-Z0-9]{1,}$/", $comments) == 0 && !$error) { $error = "The comments you entered must contain only letters or numbers."; } if(!$error) { $query = mysql_query("INSERT INTO discussion (question, comments) VALUES ('".$question."', '".$comments."')"); if($query) { } else { $error = "There was a problem with the registration. Please try again."; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/263187-submit-multiple-inputs-can-only-do-1/ Share on other sites More sharing options...
.josh Posted May 26, 2012 Share Posted May 26, 2012 1) did you echo $comments to see if it contains expected value? 2) do you have a comments column in your db table? 3) Is the question being inserted okay, just not the comment? Quote Link to comment https://forums.phpfreaks.com/topic/263187-submit-multiple-inputs-can-only-do-1/#findComment-1348845 Share on other sites More sharing options...
justlukeyou Posted May 26, 2012 Author Share Posted May 26, 2012 1. successfully echoes a test comment manually entered into db 2. yep 3. with this code nothing is being inserted into the db. When I base the code on just questions only this enters. When I try to write code for both questions and comments nothing enters. Quote Link to comment https://forums.phpfreaks.com/topic/263187-submit-multiple-inputs-can-only-do-1/#findComment-1348847 Share on other sites More sharing options...
justlukeyou Posted May 26, 2012 Author Share Posted May 26, 2012 Sorted now, I was being a silly sausage. I didn't set the form box to post to the db. Quote Link to comment https://forums.phpfreaks.com/topic/263187-submit-multiple-inputs-can-only-do-1/#findComment-1348848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.