Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Mon Aug 30, 2004 3:32 pm
I have a form with a multiple selectable list in it. When the page posts to another php page, it only shows that the last selection of the list is passing. Here is my code:
Code: Select all
<form name="form" method="post" action="dump.php" target"_post">
<p>Select table(s) to export:<br>
<select name="tables" size="6" multiple="multiple">
<option value="con_news">con_news</option>
<option value="user_info">user_info</option>
<option value="var_econtrolversions">var_econtrolversions</option>
<option value="var_level">var_level</option>
</select>
<br>
<br>
dump format:</p>
<table width="200">
<tr>
<td><label>
<input type="radio" name="format" value="SQL">
SQL</label>
</td>
</tr>
<tr>
<td><label>
<input type="radio" name="format" value="Excel CSV">
Ms Excel</label>
</td>
</tr>
</table>
<br>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
And the dump.php file:
Code: Select all
$tables = $_POST['tables'];
$format = $_POST['format'];
echo $tables;
echo $format;
exit();
Any ideas?
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Mon Aug 30, 2004 4:42 pm
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Wed Sep 01, 2004 1:03 pm
I tried as you said
timvw . The code works, but now I cannot get it into a variable. Here is my code:
Code: Select all
<$php
if (isset($_REQUEST['tables'])) {
while (list ($key, $val) = each ($_REQUEST['tables'])) {
echo "$val, ";
}
}
$format = $_REQUEST['format'];
echo $format;
exit();
?>
I need to echo it into a query later so I need it like $format.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Sep 01, 2004 1:14 pm
Code: Select all
$safe_list = array('format','tables');
foreach($safe_list as $v)
$$v = isset($_POST[$v]) ? $_POST[$v] : (isset($_GET[$v]) ? $_GET[$v] : '');
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Wed Sep 08, 2004 1:31 pm
feyd, your code is much too complex for me. I tried to get it to work, but I cannot figure out how to use it. Could you explain or give the code with the original?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Sep 08, 2004 1:36 pm
Code: Select all
$safe_list = array('format','tables');create a list of keys that are accepted into the script.
iterate through the keys in the safe list.
Code: Select all
$$v = isset($_POSTї$v]) ? $_POSTї$v] : (isset($_GETї$v]) ? $_GETї$v] : '');create a variable named the accepted/expected key. If it was posted, use that. If it was in the get, use that. Otherwise, an empty string.
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Fri Sep 10, 2004 8:50 am
Maybe I'm using your code wrong... I have this now:
Code: Select all
<?php $safe_list = array('format','tables');
foreach($safe_list as $v) $$v = isset($_POST[$v]) ? $_POST[$v] : (isset($_GET[$v]) ? $_GET[$v] : '');
echo $v;
//$format = $_REQUEST['format'];
//echo $format;
exit(); ?>
It is returning "tables" and that's it. My echo for $format works fine. I can use that, so I thought of pulling it out of code there.
The user selects "sel1", "sel2", "sel3" in the 'tables' field of the form and selects "selA" in the 'format' field of the same form. They hit GO. And it should return this:
sel1, sel2, sel3, selA
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Fri Sep 10, 2004 9:39 am
$v variable holds the name of variable to be imported. Use your names ($format, $tables) after foreach part
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Fri Sep 10, 2004 9:50 am
I changed the code echo:
Code: Select all
<?php
ehco $tables;
echo $format;
exit();
?>
echo $tables returns "Array". Not the value(s) in the variable. echo $format works fine though.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Fri Sep 10, 2004 10:24 am
AliasBDI wrote:
echo $tables returns "Array". Not the value(s) in the variable. echo $format works fine though.
because echo won't print arrays. try this:
Code: Select all
if(is_array($table)) print_r($table); else echo $table;
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Fri Sep 10, 2004 10:40 am
OK. it is echoing the Array now. I'm sorry, I didn't know that echo would not work. After all of this work, this is not what I was looking for. I'm trying to the multi-select field into a variable so that I can use it in a query under the SELECT $tables .... So I need it to show like "sel1, sel2, sel3". Am I not getting it right?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Sep 10, 2004 10:42 am
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Fri Sep 10, 2004 10:56 am
Perfect... Thanks for the help. Here is the code:
Code: Select all
<?php
$safe_list = array('format','tables');
foreach($safe_list as $v) $$v = isset($_POST[$v]) ? $_POST[$v] : (isset($_GET[$v]) ? $_GET[$v] : '');
$tables = implode(', ', $tables);
echo $tables;
echo $format;
exit();
?>
Thanks guys!