krappleby025
Programmer
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
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("$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