Jump to content

If function and database help!!


ericburnard

Recommended Posts


Hi the. Its been a good few years since i last played around with coding anything, and i decided the other day to see what i could come up with again. But ive hit a problem. Could you tell me if the following code is allowed. Ive split the IF function up so that the elseif can be repeated as many times as it needs to.

 

Here is the code:

 

<?

include ('db.php');

ob_start();

$cookie=$_COOKIE["d_login"];

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM deptabs WHERE dep='$cookie'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

if($_GET['page']==logoff){
header('location: http://ericburnard.freehostia.com/logoff.php');
}

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$tab=mysql_result($result,$i,"tab");
$link=mysql_result($result,$i,"link");
$dep=mysql_result($result,$i,"dep");


elseif ($_GET

==$id){
header('location: http://ericburnard.freehostia.com/$link');
}

$i++;

}

else {
echo "Sorry Page Not Found";
}
ob_end_flush();
?>

 

And here is the error im getting:

 

Parse error: parse error, unexpected T_ELSEIF in /home/www/ericburnard.freehostia.com/test.php on line 31

 

Pointers in the right direction would be awesome.

Chears

Eric x

Link to comment
https://forums.phpfreaks.com/topic/126998-if-function-and-database-help/
Share on other sites

In the manner you are attempting it isn't. Your code doesn't make sense.

 

I'm just guessing but try this out:

 

<?php
include ('db.php');

ob_start();

$cookie=$_COOKIE["d_login"];

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM deptabs WHERE dep='$cookie'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

if($_GET['page'] == "logoff"){
header('location: http://ericburnard.freehostia.com/logoff.php');
exit;
}else{

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$tab=mysql_result($result,$i,"tab");
$link=mysql_result($result,$i,"link");
$dep=mysql_result($result,$i,"dep");


if($_GET['page'] == $id){
header("Location: http://ericburnard.freehostia.com/{$link}");
exit;
}

$i++;

}

//If it got here, then display the page not found.
echo "Sorry Page Not Found";

ob_end_flush();
?>
[/code[

In the manner you are attempting it isn't. Your code doesn't make sense.

 

I'm just guessing but try this out:

 

<?php
include ('db.php');

ob_start();

$cookie=$_COOKIE["d_login"];

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM deptabs WHERE dep='$cookie'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

if($_GET['page'] == "logoff"){
header('location: http://ericburnard.freehostia.com/logoff.php');
exit;
}else{

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$tab=mysql_result($result,$i,"tab");
$link=mysql_result($result,$i,"link");
$dep=mysql_result($result,$i,"dep");


if($_GET['page'] == $id){
header("Location: http://ericburnard.freehostia.com/{$link}");
exit;
}

$i++;

}

//If it got here, then display the page not found.
echo "Sorry Page Not Found";

ob_end_flush();
?>
[/code[

 

I gave that a go but got unexpected $ as an error which is only the closing bracket of the php ?>

Yeah my bad, try this:

 

<?php
include ('db.php');

ob_start();

$cookie=$_COOKIE["d_login"];

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM deptabs WHERE dep='$cookie'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

if($_GET['page'] == "logoff"){
header('location: http://ericburnard.freehostia.com/logoff.php');
exit;
}else{

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$tab=mysql_result($result,$i,"tab");
$link=mysql_result($result,$i,"link");
$dep=mysql_result($result,$i,"dep");


if($_GET['page'] == $id){
header("Location: http://ericburnard.freehostia.com/{$link}");
exit;
}

$i++;

}

}

//If it got here, then display the page not found.
echo "Sorry Page Not Found";

ob_end_flush();
?>

Ok ive tried that. When p go to ?page=1 i get

 

if(1==logoff){ header('location: http://ericburnard.freehostia.com/logoff.php'); } else { echo 'Sorry Page Not Found' } 

 

For every other page number i get sorry page not found.

Ive deleted my cookies loged in again as admin (admin pages are 3 and 4), and when i go on pages 3 and 4 i still get "sorry page not found".

At least there is no error this time :D

ok i have taken the exit bit ot from here

 

if($_GET['page'] == $id){
header("Location: http://ericburnard.freehostia.com/{$link}");
exit;
}

 

It dosnt work when i go to the page but when i refresh the page it will load the right page.

Any ideas anyone??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.