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');

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

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.