Could someone tell me what I'm doing wrong?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Code: Select all

echo $comic, '<br /><a href="', $_SERVER&#1111;'PHP_SELF'], '?comic=', $comic, '&funct=2">click</a>';
This is not the error, but why use a , instead of .

EDIT/UPDATE:
To output one or more strings i read it on php.net.
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

I copied

Code: Select all

<html><body><?php 
$funct = (!empty($_GET['funct'])) ? $_GET['funct'] : 5; 
$comic = (!empty($_GET['comic'])) ? $_GET['comic'] : 3; 

if ($funct == 2) { 
   $comic = $comic - 1; 
   if ($comic < 1) { 
      $comic = 1; 
   } 
} 
echo $comic, '<br /><a href="', $_SERVER['PHP_SELF'], '?comic=', $comic, '&funct=2">click</a>'; 
?></body></html>
But no error's here.
php 4.2.3 @ Linux
marshie
Forum Newbie
Posts: 14
Joined: Thu May 01, 2003 10:04 pm

Post by marshie »

There's got to be something wrong with the server, or maybe it's not supporting the $funct = (!empty($_GET['funct'])) ? $_GET['funct'] : 5; lines. Is there another way I can do them?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

twigletmac wrote: BTW, doing:

Code: Select all

<?php $funct = (!empty($_GET['funct'])) ? $_GET['funct'] : 5; ?>
is a shorter way of writing:

Code: Select all

<?php
if (!empty($_GET['funct'])) {
    $funct = $_GET['funct'];
} else {
    $funct = 5;
}
?>
and what it does is get the value of funct from the query string in the URL if it's there and if not sets it to a default value of 5 (or whatever you like).
marshie
Forum Newbie
Posts: 14
Joined: Thu May 01, 2003 10:04 pm

Post by marshie »

Oh yeah. :)

Nope, still no luck. Error on line 15. Here's the code I have now.
<html>
<body>
<table align="left" border="0" cellpadding="10" cellspacing="0">
<tr>
<td>Test1</td>
</tr>
<tr>
<td>Test2</td>
</tr>
</table>

<?php

if (!empty($_GET['funct'])) {
   $funct = $_GET['funct'];
} else {
    $funct = 5;
}

if (!empty($_GET['comic'])) {
    $comic = $_GET['comic'];
} else {
    $comic = 3;
}

if ($funct == 2) {
$comic = $comic - 1;
if ($comic < 1) {
$comic = 1;
}
// use elseif not a separate if for this
} elseif ($funct == 3) {
$comic = $comic + 1;
if ($comic > 3) {
$comic = 3;
}
} elseif ($funct == 4) {
$comic = 3;
} elseif ($funct == 5) {
$comic = 1;
}

echo '<img src="http://members.lycos.co.uk/comicsforpub ... omic.'.jpg">';

<a href="test.php?funct=2&comic=<?php echo $comic; ">back</a>
<a href="test.php?funct=3&comic=<?php echo $comic; ">forward</a>
<a href="test.php?funct=4&comic=<?php echo $comic; ">latest</a>
<a href="test.php?funct=5&comic=<?php echo $comic; ">first</a>
</body>
</html>
There has got to be some way to get this to work. I swear, no matter how long it takes me, I am going to find a way to do this. :P
marshie
Forum Newbie
Posts: 14
Joined: Thu May 01, 2003 10:04 pm

Post by marshie »

I think I have an idea. How can I say "if ($funct = doesnotexist)" without using that !GET function?
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Maybe try:
if (empty($funct)) {
$funct = 5;
}

if (empty($comic)) {
$comic = 3;
}

The $funct is allready set to the $_POST['funct'] content.
So you can check if it's empty or even isset($comic) will do now.
marshie
Forum Newbie
Posts: 14
Joined: Thu May 01, 2003 10:04 pm

Post by marshie »

Woohoo!! I FINALLY got it!! Check it out. :D
<html>
<?php

$latest = 3;

if (empty($funct)) {
$comic = $latest;
}

if ($funct == 2) {
$comic = $comic - 1;
if ($comic < 1) {
$comic = 1;
}
}

if ($funct == 3) {
$comic = $comic + 1;
if ($comic > 3) {
$comic = 3;
}
}

if ($funct == 4) {
$comic = 1;
}


echo '<img src="http://members.lycos.co.uk/comicsforpub ... omic.'.jpg">';

?>

<a href='test.php?funct=2&comic=<?echo ("$comic")?>'>back</a>
<a href='test.php?funct=3&comic=<?echo ("$comic")?>'>forward</a>
<a href='test.php?comic=<?echo ("$latest")?>'>latest</a>
<a href='test.php?funct=4'>first</a>
</body>
</html>
It works perfectly now! I'm finally done! DONE!! *murders Tripod*

Thanky you all very much for your help, I really really appreciate it. :)
Post Reply