|
Subject:
|
database problem?
|
|
Posted By:
|
hosefo81
|
Post Date:
|
1/6/2004 7:35:19 PM
|
i have a problem but i don't know why the code doesn't works. i query using the data submitted in the previous php page. The first time i use $_POST[text] to retrieve data, it works but later it doesn't works with other queries.
//a previous example that use $_POST['text1'] works select b.brand_name, sum((sd.sales_price * sd.quantity)) as Sales from product p, sales_detail sd, sales s, category c, brand b where sd.sales_id=s.sales_id and p.prod_id=sd.prod_id and c.cat_id=b.brand_cat and p.prod_brand = b.brand_id and year(s.sales_date) between $_POST[yearSalesStart] and $_POST[yearSalesEnd] and c.cat_id=$_POST[text1] group by b.brand_name order by Sales desc";
Below are my code that doesn't work: select p.prod_name, sum((sd.sales_price * sd.quantity)) as Sales from product p, sales_detail sd, sales s, category c, brand b where sd.sales_id=s.sales_id and p.prod_id=sd.prod_id and c.cat_id=b.brand_cat and p.prod_brand = b.brand_id and year(s.sales_date) between $_POST[yearSalesStart] and $_POST[yearSalesEnd] and b.brand_id=$_POST['text1'] group by p.prod_name order by Sales desc";
i get the following error: Fatal error: Call to undefined function: error_message() in c:\inetpub\wwwroot\project\processreport.php on line 103
//However when i substitute $_POST['text1'] by a brand_id, it works. select p.prod_name, sum((sd.sales_price * sd.quantity)) as Sales from product p, sales_detail sd, sales s, category c, brand b where sd.sales_id=s.sales_id and p.prod_id=sd.prod_id and c.cat_id=b.brand_cat and p.prod_brand = b.brand_id and year(s.sales_date) between $_POST[yearSalesStart] and $_POST[yearSalesEnd] and b.brand_id='br13' group by p.prod_name order by Sales desc";
Please help!!!!!
|
|
Reply By:
|
nikolai
|
Reply Date:
|
1/6/2004 7:45:16 PM
|
You're not consistent with your quoting style.
When substituting an string-indexed array element in a double-quoted string, you don't need to quote the index:
<?php
$person = array("name" => "Nikolai", "city" => "San Diego"); echo "His name is $person[name]."
?>
That's because within a string, if PHP sees a variable identifier (e.g. $person, $foo) followed by an opening square bracket, PHP assumes that the variable is an array, and that the index is everything up to the first closing square bracket.
This index can either be a number, a string, or another variable. A single-quote mark is an invalid character to begin a simple string index, so PHP throws an error.
To accomodate more complex string or nested indexes, PHP supports the curly-brace syntax. Within curly braces, you must quote all your indexes as if you were not within a double-quoted string.
To make a long story short, you need to either remove the single-quotes from $_POST['text1'], or put $_POST['text1'] in curly-braces.
For more information, I strongly suggest you read this page: http://www.php.net/types.string
Take care,
Nik http://www.bigaction.org/
|
|
Reply By:
|
hosefo81
|
Reply Date:
|
1/8/2004 8:09:04 AM
|
$_POST['text1'] is a typing error when i post it. Actually i type $_POST[text1] in the query and the same error occured. so the problem is not because of the quoting style. Is there any other possiblity for the problem?
|
|
Reply By:
|
nikolai
|
Reply Date:
|
1/8/2004 4:38:19 PM
|
I think you're not showing us enough code, then. The error message you're getting says that you're trying to call a function called "error_message()" that doesn't exist.
Take care,
Nik http://www.bigaction.org/
|
|
Reply By:
|
hosefo81
|
Reply Date:
|
1/9/2004 8:00:48 AM
|
the problem is solved!!! i just type \"$_POST[text1]\" instead of $_POST[text1] and it works fine.
|