Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User-Defined Variable & mySQL query

Status
Not open for further replies.

Andy3L

IS-IT--Management
May 7, 2004
4
GB
Hi,

I am trying to use input from an HTML form, 'post' this numeric value and (using PHP) query it against a mySQL database. This all works if I 'manually' enter the value (eg .'100') into the code/script but I cannot amend the value via an HTML 'edit' <INPUT> box.

Please find to follow my code:

<form method="post" action="matchingbills_curAZL.php" name=norwel>
<table>
<tr>
<td>Select an Office: </td>
<td><select name="s_office"><option value=p4norint selected>London</option><option value=p4exeint>Exeter</option><option value = p4manint>Manchester</option></select></td></tr><tr>
<td>Select Money on Matter: </td>
<td><select name="s_balance">
<option default value="and matter.bills_bal+cur_bal=0">Exactly</option>
<option value="and matter.bills_bal + cur_bal between -100 and 100">Within £100</option>

<!-- THIS LINE DOES NOT WORK - I NEED TO SOMEHOW BE ABLE TO USE THE USER-DEFINED VALUE "$s_min_balance" FOR EACH POSTING OF THE FORM. THE FORM DOES WORK FOR 'HARDCODED VALUES eg. '0' & '100'.

IS THERE A WAY TO INCLUDE php IN THE mySQL QUERY STRING OR MUST IT BE RESOLVED OUTSIDE OF THE QUERY AND THEN REFERRED TO IN EXECUTION?
-->
<option value="and matter.bills_bal + cur_bal between <?php -$s_min_balance ?> and <?php $s_min_balance ?>">Enter Value Below ...</option>
</select>
</td></tr>

<tr valign=top>
<td>Select minimum balance<br>to obtain a selective report: </td>
<td><input name="s_min_balance"></td>

</table>
</form>

It falls over when executing the query:
Warning: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 12: Incorrect syntax near 's_min_balance'., SQL state 37000 in SQLExecDirect in C:\Inetpub\ on line 100
Unable to query Norwel Database

Any help would be greatfully appreciated.
Thanks
Andy
 
First of all, you have SQL code visible in HTML. This is an extraordinarily bad idea. Set integer values for your options and have your PHP script create the SQL statement from those returned values.

Second, in the PHP forum I have placed a FAQ, faq434-2999, which covers debugging database code.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top