Jump to content

Submit Multiple Inputs (can only do 1)


justlukeyou

Recommended Posts

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.";
        }
    }
}

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/263187-submit-multiple-inputs-can-only-do-1/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.