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
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[

Link to comment
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[

 

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

Link to comment
Share on other sites

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();
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.