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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.