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

result problem (newbie question)

Status
Not open for further replies.

krappleby025

Programmer
Joined
Sep 6, 2001
Messages
347
Location
NL
hi all, im having a problem with functions, its the first time i have used them. can you help

firstly the function

function Main_page($id)
{
$query = "select * from Members where ID = '$id'";
$result = mysql_query($query) or die ("couldn't execute query");
IF ($result == "" )
{
$query3 = "SELECT * FROM Members ORDER BY rand() LIMIT 1 ";
$result = mysql_query($query3) or die ("couldn't execute query");
while ($row = mysql_fetch_array($result) )
{
extract($row);
$ids = $ID;
}
}
while ($row = mysql_fetch_array($result) )
{
extract($row);
$ids = $ID;
}


$query4 = "select * from Members where ID = '$ids'";
$result = mysql_query($query4) or die ("couldn't execute query");
while ($row = mysql_fetch_array($result) )
{
extract($row);
setcookie ("SponsorID", "$username",time()+$cookie_timeout);
setcookie ("Firstname", "$First_Name",time()+$cookie_timeout);
setcookie ("Lastname", "$Last_Name",time()+$cookie_timeout);
}

}


Then the code used to call the function

if ($page == "1") # Main page info collect and set the sponsor
{
Main_page("$id");
}

NOTE : $ids is sent to the page in the url.. ie ?page=1

now..

The code above appears correct, (but i dont know) and this script is not placing anything in the cookies, it is supposed to check to see if there is a record one, and if there isnt select a random record, and place the results of either record in the cookies, but its not doing it

any ideas will be a great help

thanks

keith
 
sorry should be

NOTE : $id is sent to the page in the url.. ie ?page=1
 
Question:
Are you sure $id actually contains something?

Your code relies on register_globals set to ON which is not the default since PHP 4.2.0
Read:

Print out $id for a check. Also, if your PHP version is 4.2.0 or later you can be sure register_globals is OFF. Refer to the passed variables through the $_POST, $_GET etc. superglobal arrays.
 
You're using include across the web? The included file is on another machine?

Keep in mind in these circumstances that the include() invocation instigates a connection to a web server. What will be returned will not be PHP code, but rather HTML output. Is this what you want?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
from the code i read my global is on.. because the result works, and carries through the variable, however this script just isnt producing the effect it should

thanks
 
sleipnir214

no the file is on the same server but i canot just use the command include("GPAscript.php?page=1"); it just comes up wiht a load of errors

thanks
 
ok i have changed the script slightly to make it easier for me.. now i call the page with

include("
and the script is now

if ($page == "1")
{
$query = "select * from Members where ID = '$id'";
$result = mysql_query($query) or die ("couldn't execute query");
while ($row = mysql_fetch_array($result) )
{
extract($row);
$ids = $ID;
}
$query3 = "SELECT * FROM Members ORDER BY rand() LIMIT 1 ";
$result = mysql_query($query3) or die ("couldn't execute query");
while ($row = mysql_fetch_array($result) )
{
extract($row);
$ids2 = $ID;
}
IF ($ids == "" )
{
$ids = $ids2;
}

$query4 = "select * from Members where ID = '$ids'";
$result = mysql_query($query4) or die ("couldn't execute query");
while ($row = mysql_fetch_array($result) )
{
extract($row);
setcookie ("SponsorID", "$username",time()+$cookie_timeout);
setcookie ("Firstname", "$First_Name",time()+$cookie_timeout);
setcookie ("Lastname", "$Last_Name",time()+$cookie_timeout);
}
}

now it is reading the script because if i put an echo in the script. it displays the $id, however its not working still.. its not changing the $id number to a valid record..

I dont understand this at all the script looks good

thanks
 
the funniest thing is if i echo $ids, it produces the same number as the $id

 
Uless you're trying to test or use a home-grown web service of some kind, I see no reason to perform an HTTP include() across the same server. You'll get better performance using a filesystem include of the file.

With the code you've posted, this:

nclude("
And this:

$id = <somevalue>;
$page = <somevalue>;
include ('GPAscript.php');

are equivalent and the latter will give you much better performance.


In terms of what you're trying to do in the included file, I don't understand what &quot;its not changing the $id number to a valid record&quot; means. I know you aren't referring to updating MySQL records, because you have no INSERT of UPDATE queries in the cod you've posted.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
ok..

simply put, this code, checks a database, and if there is a record sets $ids. It then runs the second part of the script to choose a random record and sets that as $ids2. then it checks there is a result in $ids and if there isnt it sets $ids2 as $ids.

it then runs the final part of the script, and sets the cookies, corresponding to the record that is in the $ids record

There are only two records in the database $id 1 and $id 2

the reason the code is as it is, is because it is for a friend, and he dont know php programming, so i need to make it easy to add the script to his site, so using includes will solve the problem.

The includes statement works, it sends the correct variables accross, but the script is not working. this is what i dont understand

I am only a beginner and have only been programming for 15 days.. but to me and my book the script looks correct. lol

any ideas

and thanks for the help
 
Yes, use an include. However, don't use an include across HTTP. Trust me, your friend will get better performance. Also, depending on your friend's server's settings, using include() with a URL may not be allowed. Just include the file across the filesystem, don't use &quot; in the include unless you absolutely need to -- and that's only insituations where the file you have to include is on another server.


&quot;Not working&quot; is pretty vague. What does it mean when used to refer to this script?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top