I have a form that contains names of columns in a select. How do I pass the value of that select into a mysql statement.
Here is part of my code:
The mysql table is:
id-cash-credit_cards-bill_to_room

The form is:

<form action="display.php" method="post">
<select name="show_by" id="show_by" onchange="submit()">
	<option value="">--Select--</option>
	<option value="cash">Cash</option>
	<option value="credit_cards">Credit Cards</option>
	<option value="bill_to_room">Bill To Room</option>
	<option value="ten_minutes">Ten Minutes</option>
</select>

Then display.php has the following

$result = mysql_query("SELECT property, SUM('$_POST[show_by]') as total FROM table");

Why this doesn't work?
Thanks.

    Without information about what "doesn't work" means or any error messages given, I'd suspect that the problem is a failure to GROUP BY property.

      Also, doing sum on strings will not work and is nonsensical. What are you trying to achieve? And you need to escape user input, or you risk SQL injection.

        Write a Reply...