Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trying to pass variable to include file

Participant ,
Jan 22, 2009 Jan 22, 2009
I have a page that is called by using $_GET[cust_name]
It brings up info for the customer, name address, etc.
I have included a file "quotes.php" by <?php include "quotes.php";?>
Where I have an SQL statement:

$query_quotes = "SELECT * FROM quotes LEFT JOIN customer ON quotes.cust_id = customer.cust_id WHERE cust_business_name = '$_GET[cust_name]'";
$quotes = mysql_query($query_limit_quotes, $db) or die(mysql_error());
$row_quotes = mysql_fetch_assoc($quotes);
$totalRows_quotes = mysql_num_rows($quotes);

All it returns is Query is Empty.

Now I tried using sessions and the same thing happens.
How can I fix this?

I have comments system very much like this but it is called by a variable thru the URL, It should work this way.
TOPICS
Server side applications
390
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 22, 2009 Jan 22, 2009
.oO(The_FedEx_Guy)

>I have a page that is called by using $_GET[cust_name]
> It brings up info for the customer, name address, etc.
> I have included a file "quotes.php" by <?php include "quotes.php";?>
> Where I have an SQL statement:
>
> $query_quotes = "SELECT * FROM quotes LEFT JOIN customer ON quotes.cust_id =
^^^^^^^^^^^^^
>customer.cust_id WHERE cust_business_name = '$_GET[cust_name]'";
> $quotes = mysql_query($query_limit_quotes, $db) or die(mysql_error());
^^^^^^^^^^^^^^^^^^^
> $row_quotes = mysql_fetch_assoc($quotes);
> $totalRows_quotes = mysql_num_rows($quotes);
>
> All it returns is Query is Empty.

Check your error reporting, you should have received an E_NOTICE error,
telling you that $query_limit_quotes is undefined. Additionally the
script is vulnerable to SQL injection through the cust_name parameter.

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 22, 2009 Jan 22, 2009
The file is included by the server before any of the code is executed.
There is no 'passing variables to include file' necessary since the code
from that include is already in the page at the time of execution.

I suspect that there is some other problem which you can troubleshoot by
selectively inserting echo statements at logical points in your code to
visualize how the data is being used.

> Now I tried using sessions and the same thing happens.
> How can I fix this?

Session variables would work as well - did you initialize the session before
using them?

<?php if(!isset($_SESSION)) { session_start(); } ?>

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"The_FedEx_Guy" <webforumsuser@macromedia.com> wrote in message
news:gl9oa4$o4m$1@forums.macromedia.com...
>I have a page that is called by using $_GET[cust_name]
> It brings up info for the customer, name address, etc.
> I have included a file "quotes.php" by <?php include "quotes.php";?>
> Where I have an SQL statement:
>
> $query_quotes = "SELECT * FROM quotes LEFT JOIN customer ON quotes.cust_id
> =
> customer.cust_id WHERE cust_business_name = '$_GET[cust_name]'";
> $quotes = mysql_query($query_limit_quotes, $db) or die(mysql_error());
> $row_quotes = mysql_fetch_assoc($quotes);
> $totalRows_quotes = mysql_num_rows($quotes);
>
> All it returns is Query is Empty.
>
> Now I tried using sessions and the same thing happens.
> How can I fix this?
>
> I have comments system very much like this but it is called by a variable
> thru
> the URL, It should work this way.
>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 22, 2009 Jan 22, 2009
Yes, I did initialize the session.
I've reverted back to the included example.
Its not working but I will come back to it later.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 23, 2009 Jan 23, 2009
I'm still getting Query was empty :'(
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 23, 2009 Jan 23, 2009
Solved problem.

($query_limit_quotes, $db) should have been:
($query_quotes, $db)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 23, 2009 Jan 23, 2009
LATEST
.oO(The_FedEx_Guy)

>Solved problem.
>
>($query_limit_quotes, $db) should have been:
>($query_quotes, $db)

Which I already told you (more or less) in my first reply. ;-)

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines