Select option from dropdown, then echo to php var.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello guys I am new to the php world. This is my first php file, I was asked by my boss to create a php file that will export to a specific msql database.  
Funny thing is I am not really having trouble exporting the information but storing the right information in the php variables. TLDR: My question: would the code below work? if not how do I fix it?

$problemCategory = check_input($_POST['problemCategory'], "Enter Case Category");

Select <b>Case Category</b>:  
<select name = "problemCategory">
<option value = "">Select option</option>
<option value = "Hard Drive">Hard Drive</option>
<option value = "Power Supply">Power Supply</option>
<option value = "Memory">Memory</option>
<option value = "System Board">System Board</option>
<option value = "Fan">Fan</option>
<option value = "NIC">NIC</option>
<option value = "Other">Other</option>

<?php echo $problemCategory; ?><br />
<br />

Re: Select option from dropdown, then echo to php var.

On Mon, 03 Aug 2015 11:06:03 -0700, Jonathan H wrote:

Quoted text here. Click to load it


check_input does not appear to be a standard php function, and you have  
given no code for the check_input function you areusing, so it is hard to  
determine what it does.

Drawing a line under your code, here is a simple example of a php file  
that generates an html form and then processes the form data when the  
form is submitted. Save it as basic_form.php (or change the file name in  
the action attribute of the form element to match the file name).

You need to understand that this is a multi step process. First you send  
the form to the browser. Then the browser sends the post data back. Then  
you process the post data and generate some new output to the users  

Study and understand it to get the basic concepts under your belt. Note  
carefully that thus form has no protection whatsoever against a malicious  
attack on your website by manipulating the values of the $_POST data.

Note that your code does not define a form, and does not appear to  
separate form processing and html generation. You have not provided the  
glue that will send the user input back to be processed by the php code  
(ie the html form element).


// form processing

if (isset($_POST) && count($_POST))
    $data = "<hr>\n<pre>\n" . print_r($_POST, TRUE) . "\n</pre>\n";
    $data = "";

// html generation

echo <<< EOT
<title>basic form test</title>
<form method='post' action='basic_form.php'>
Words: <input name='words' type='text'><br>
Choice: <select name='choice'>
<option value='0'>Choice 0</option>
<option value='1'>Choice 1</option>
<option value='2'>Choice 2</option>
<option value='3'>Choice 3</option>
<input type='submit'>


Denis McMahon,

Site Timeline