Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #15628

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

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.php
Subject Re: Select option from dropdown, then echo to php var.
Date 2015-08-04 00:31 +0000
Organization A noiseless patient Spider
Message-ID <mpp145$os0$7@dont-email.me> (permalink)
References <af055149-26bf-43a6-9eaf-b78bc64d6aa1@googlegroups.com>

Show all headers | View raw


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, denismfmcmahon@gmail.com

Back to comp.lang.php | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Select option from dropdown, then echo to php var. Jonathan H <hauxwellj@gmail.com> - 2015-08-03 11:06 -0700
  Re: Select option from dropdown, then echo to php var. Denis McMahon <denismfmcmahon@gmail.com> - 2015-08-04 00:31 +0000

csiph-web