Wrox Programmer Forums
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 6th, 2004, 08:35 PM
Authorized User
 
Join Date: Oct 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default database problem?

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!!!!!


 
Old January 6th, 2004, 08:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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/
 
Old January 8th, 2004, 09:09 AM
Authorized User
 
Join Date: Oct 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

$_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?


 
Old January 8th, 2004, 05:38 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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/
 
Old January 9th, 2004, 09:00 AM
Authorized User
 
Join Date: Oct 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the problem is solved!!! i just type \"$_POST[text1]\" instead of $_POST[text1] and it works fine.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem to restore database in C#2005 database acmuralee MySQL 0 March 25th, 2008 04:42 AM
DATABASE PROBLEM. PLEASE HELP! dextergaisie Crystal Reports 2 May 15th, 2007 05:58 AM
database problem rahul8346 SQL Server 2000 1 May 16th, 2006 11:13 AM
Database Problem kanoorani Beginning VB 6 3 April 27th, 2006 02:16 AM
problem for the database rachelwang All Other Wrox Books 2 August 4th, 2003 02:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.