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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I do this?

Status
Not open for further replies.

Phutie

Programmer
Jul 31, 2000
29
PH
Hi,

How can I query a database in another php file where the variable I want to
query is referenced on another page?

Ex.

$LinkName is on File A

on File B I want to do this

$sql = ( "SELECT Email from Listings WHERE Company LIKE '$LinkName'");
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$emailvar = $row[0];

When I do this, it gives me an error "0 is not a Mysql index......" I tried
using include() but doesn't work too. Actually, File B is called by this
code,

print '<FORM NAME=&quot;email&quot; METHOD=POST ACTION=&quot;fileb.php3&quot;>
<INPUT TYPE=HIDDEN NAME=&quot;PHORM_CONFIG&quot; VALUE=&quot;feedbackconfig.inc&quot;>
<INPUT TYPE=HIDDEN NAME=&quot;PHORM_NOTHIN&quot; VALUE=&quot; -- &quot;>
<INPUT TYPE=HIDDEN NAME=&quot;ph_sneak&quot; VALUE=&quot;Boo!&quot;>';

Any ideas?

Phutie
 
I am not 100% sure on this, but within file B, you would have to include file A by doing this:

[tt]
include (&quot;filea.php&quot;);
[/tt]

I just recently posted a question about this on this forum (how do i use a conf file is the jist of the name).

You can read there to find out exactly how to do it.

Hope this helps.

-Vic

vic cherubini
malice365@hotmail.com
====

Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director

Wants to Know: Java, Cold Fusion, Tcl/TK

====
 
OK, ypur problem is that you have a variable called $LinkName that is undefined in file B.
for you query to succeed, you have to pass this variable from one page to the other.
either using the session object, or by referencing it on the adress.

here is an exemple for both case:
case 1
----------
File A
<?php
session_start();
$LinkName=value_of_the_link;
session_register(&quot;LinkName&quot;);
....
?>

File B
<?php
session_start();
....
put your code here.
?>
now $LinkName is defined in every page where you put a session_start();
you can unregister the variable using session_unset();
this will clear all sessions variables.

-----------
case 2
-----------
if the variable $LinkName is defined on this page :

print '<FORM NAME=&quot;email&quot; METHOD=POST ACTION=&quot;fileb.php3&quot;>
<INPUT TYPE=HIDDEN NAME=&quot;PHORM_CONFIG&quot; VALUE=&quot;feedbackconfig.inc&quot;>
<INPUT TYPE=HIDDEN NAME=&quot;PHORM_NOTHIN&quot; VALUE=&quot; -- &quot;>
<INPUT TYPE=HIDDEN NAME=&quot;ph_sneak&quot; VALUE=&quot;Boo!&quot;>';

then you can add an hidden field with
name=LinkName value=&quot;value_of_the_link&quot;

or pass it through the url :
fileB.php?LinkName=value_of_the_link


hope it helps

Regards

Khaldryck
 
Hi Khaldryck,

the session_start() gives me this error:

Fatal error: Call to unsupported or undefined function session_start()

Where shall I put it on the code?

Thanks,

Phutie
 
Hmm... probably means you're not running PHP4. Ask you system administrator to upgrade it for you.
 
Hi,

is there any other way I can do this in PHP3?

Phutie
 
It would seem most feasible to take case 2 from Khaldryck's earlier post. Just through in an <input type='hidden'> field with name='linkname' and value='$linkname'.

Here's one more thing that just popped into my head --

I've used to variable name $linkname to refer to database connections, so perhaps that's what you're trying to access? In this case, open the connection as persistant (for mysql, this is the function mysql_pconnect). You can then use the method above (which will just pass the resource id, so there's no worry of having a visible username or password sent to the client) and the link will be available permanently, no matter what page you're on.

Hope this helps.

brendanc@icehouse.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top