Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

7 views
Skip to first unread message

Denis McMahon

unread,
Aug 3, 2015, 8:32:44 PM8/3/15
to
On Mon, 03 Aug 2015 11:06:03 -0700, Jonathan H wrote:

> 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?
>
> <?php $problemCategory = check_input($_POST['problemCategory'], "Enter
> Case Category");
> ?>
> <html>
> <body>
>
> 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>
> </select>
>
> <?php echo $problemCategory; ?><br />
> <br />

-----------------------------------------

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

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

<?php

// form processing

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

// html generation

echo <<< EOT
<html>
<head>
<title>basic form test</title>
</head>
<body>
<form method='post' action='basic_form.php'>
<p>
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>
</select><br>
<input type='submit'>
</p>
</form>
{$data}
</body>
</html>
EOT;


--
Denis McMahon, denismf...@gmail.com
0 new messages