Jump to content

[SOLVED] need help w/ function, trying to grab posted value and put into function


bradkenyon

Recommended Posts

i have a small drop down form to select the table to view, i try to capture the value and put into the function to display it properly but i ran into a little problem, any help would be appreciated.

switch($_GET['mode']) 
{
	case "view":
		getTableToList();
	break;

	case "logout":
		print 'logout';
	break;

	case "export";
		print 'export';
	break;
}

 

i select to 'view'

 

then it displays me w/ the drop down menu to select from, then it is suppose to grab the value and use it within a function being called within that function.

 

kind of new to functions, so a function within a function is kind of new to me.

<?php
// -----------------------------------------------------
//list volunteers in admin section
function displayList($table, $order, $sort){
$query = "select * from $table ORDER by $order $sort";
$result = mysql_query($query);

?>
<table border="1" cellpadding="5" width="100%">
<tr>
	<th>Name</th>
	<th>Comments</th>
	<th>Venue Preference</th>
	<th>Venue</th>
	<th>Edit</th>
</tr>
<tr> <?
while($row = mysql_fetch_array($result))
{
	$i = 0;

	while($i <=0)
	{
		print '<td>'.$row['fname'].' '.$row['lname'].'</td>';
		print '<td><small>'.substr($row['comments'], 0, 32).'</small></td>';
		print '<td><small>1) '.$row['choice1'].'<br>2) '.$row['choice2'].'<br>3) '.$row['choice3'].'</small></td>';
		print '<td><small>1) '.$row['choice1'].'<br>2) '.$row['choice2'].'<br>3) '.$row['choice3'].'</small></td>';
	?>
		<td><a href="?mode=upd&id=<?= $row[id] ?>">Upd</a> / <a href="?mode=del&id=<?= $row[id] ?>" onclick="return confirm('Are you sure you want to delete?')">Del</a></td>
	<?
		$i++;
	}
print '</tr>';
}
print '</table>';
}
// -----------------------------------------------------

// -----------------------------------------------------
//get table you want to list
function getTableToList(){
print '
	<form method="post" action="?mode=view">
		<select name="table">
			<option>Select</option>
			<option value="volunteers_2009">2009 Volunteers</option>
			<option value="volunteers_2008">2008 Volunteers</option>
			<option value="maillist">Festival Updates</option>
		</select> <input type="submit" value="View" name="submit">
	</form>';

	displayList($HTTP_POST_VARS['table'], 'lname', 'ASC');

}
// -----------------------------------------------------
?>

 

 

 

I copied your code, and apart from not being able to see the database, it works for me... takes me to that function, sets up the table, and the of course errors on the queries bc i don't have access.

 

I did notice that :    case "export" is terminated with a ;... when it should be a : .  Also, you may want to set a default as well.

 

If you're still having a problem, tell us more specifically what you're expecting to happen, and what's happening instead.

when i hit submit, it seems to not post the table value, because im trying to grab the value from that drop down list, then put it into the other function to display the table i selected from the drop down.

If you are talking about the displayList()  function not getting that value...hmm

 

I replaced $HTTP_POST_VARS with $_POST, and it works on the second iteration (meaning after you submit that form)...

 

! Also, you should remove <option>Select</option> because that could mess up your table.

More specifically, you should check that the posted item is a valid name.  Meaning that $_POST['table'] has to be volunteers_2008 or volunteers_2009 or mailinglist  Otherwise you could receive a mysql injection.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.