Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6333725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:31:15+00:00 2026-05-24T18:31:15+00:00

I made a simple (yet unconventional) form which stores each answer as a variable

  • 0

I made a simple (yet unconventional) form which stores each answer as a variable (I did it this way because some questions won’t be answered because some questions showing up depend on what you answered on the previous question).

I would like to send that off to a php file which will search if there’s a match in a Mysql database, and return it in an xml format.

Here are the variables:

  • Answer1: If filled, must equal to what is in mysql
  • Checkbox1/2/3/3: Will retrieve data if one or more of these is checked. For example, if ‘coffee’ and ‘juice’ is checked, rows that have either coffee or juice set to true will be returned.
  • Dropdown1/2: Two from/to variables that specify a range

Here is my code 🙂
http://jsfiddle.net/pufamuf/S6smg/1/

HTML:

<div id="que1">Question One:
    <input id="inp1" type="text">
    <input type="button" value="Next Question" id="but1"></div>

<div id="que2" class="hiddendiv">Question Two:<br>
    <input type="checkbox" id="checkbox1" value="coffee">Coffee<br>
    <input type="checkbox" id="checkbox2" value="tea">Tea<br>
    <input type="checkbox" id="checkbox3" value="latte">Latte<br>
    <input type="checkbox" id="checkbox4" value="juice">Juice<br>
    <input type="button" value="Next Question" id="but2"></div>

<div id="que3" class="hiddendiv">Question Three:
    From:
    <select id="dropdown1">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>
    To:
    <select id="dropdown2">
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    </select>
    <input type="button" value="Finish" id="but3"></div>

<br><br><br>
<b>Variables</b><br>
Answer1:<div id="answer1"></div>
Checkbox1:<div id="answer2a"></div>
Checkbox2:<div id="answer2b"></div>
Checkbox3:<div id="answer2c"></div>
Checkbox4:<div id="answer2d"></div>
Dropdown1:<div id="answer3a"></div>
Dropdown2:<div id="answer3b"></div>

Jquery:

$("input[type='button']").click(function() {
    var question1 = '';
    var question2a = '';
    var question2b = '';
    var question2c = '';
    var question2d = '';
    var question3a = '';
    var question3b = '';
    switch (this.id) {
    case 'but1':
        question1 = $("#inp1").val();
        $("#answer1").html(question1);
        $('#que1').addClass('hiddendiv');
        $('#que2').removeClass('hiddendiv');
    break;
    case 'but2':
        if($('#checkbox1').is(':checked')){
        question2a = '1';
        }
        if($('#checkbox2').is(':checked')){
        question2b = '1';
        }
        if($('#checkbox3').is(':checked')){
        question2c = '1';
        }
        if($('#checkbox4').is(':checked')){
        question2d = '1';
        }
        $("#answer2a").html(question2a);
        $("#answer2b").html(question2b);
        $("#answer2c").html(question2c);
        $("#answer2d").html(question2d);
        $('#que2').addClass('hiddendiv');
        $('#que3').removeClass('hiddendiv');
    break;
    case 'but3':
        question3a = $("#dropdown1").val();
        question3b = $("#dropdown2").val();
        $('#que3').addClass('hiddendiv');
        $("#answer3a").html(question3a);
        $("#answer3b").html(question3b);
    break;
}
});

Thank you very much everyone :)))!

Here’s what the php file looks like now for my older html form:

<?php
require("db_access.php");

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&#39;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

$name=$_POST['name'];
$address=$_POST['address'];
$type=$_POST['type'];


// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}




// Select all the rows in the markers table
$inputs = array('name', 'address', 'type');
$where  = array();

foreach($inputs as $input)
{
    if(!empty($_POST[$input])) {
        $where[] = "{$input} = '" . mysql_real_escape_string($_POST[$input]) . "'";
    }
}

if ($where) {
    $query = 'SELECT * FROM markers WHERE ' . implode(' AND ', $where);
} else {
    user_error("No rows returned by:<br />\n$query"); 
}
$result = mysql_query($query);
if($result == false) {
   die(mysql_error() . "<br />\n$query");
}
if(mysql_num_rows($result) == 0) {
   user_error("No rows returned by:<br />\n$query");
} 

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'type="' . parseToXML($row['type']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo '/>';
}

// End XML file
echo '</markers>';

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:31:17+00:00Added an answer on May 24, 2026 at 6:31 pm

    You need to make an HTTP request to the PHP page, and handle the form data on the server side. Depending on the form type, it will be in either $_GET or $_POST.

    If you want to do it using AJAX, you can use a form plugin or do it manually by collecting the data and submitting it with $.get.

    1. Assign a name value to each form element.
    2. Use the name to pull the form data from the, for example, if the field is named foo and you’re requesting data with POST, you would use $_POST['foo']
      .
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a simple http server using Twisted, which sends the Content-Type: multipart/x-mixed-replace header.
I have made a simple test application for the issue, two winforms each containing
Possible Duplicate: How does StackOverflow generate its SEO-friendly URLs? I made a simple form
I've made this simple logout script: <?php session_start(); $db_connect = mysql_connect('localhost', 'root', '*****'); if(!$db_connect)
I'm looking for a way to have a simple form (yes and no radio
Hi all this one surely is a simple one but I haven't made sense
On Windows, testing different OSes is made simple using VMs. Is there a simple
We made a simple application and using GoogleAppEngineLauncher (GAEL) ran that locally. Then we
I made a simple counter, but it increments by 2 instead of 1. $handle
I've made a simple OpenCV application with Visual Studio 2008 and I've built it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.