/    Sign up×
Community /Pin to ProfileBookmark

Simple php question…

Hi !!!
I have this page :

[code=php]
<?php
// SQL database Variables
$hostname=”sql.free.fr”;
$user=”username”;
$pass=”passwd”;
$dbase=”dbname”;
$connection = mysql_connect(“$hostname” , “$user” , “$pass”);
$db = mysql_select_db($dbase , $connection);

$getid = $_GET[‘pagetitle’];
$url = “http://enfantsdelo.free.fr/persosphp.php”;

$pagetitle = mysql_result(mysql_query(“SELECT pagetitle FROM persos WHERE PAGETITLE=’$getid'”,$connection),0);
$title = mysql_result(mysql_query(“SELECT title FROM persos WHERE PAGETITLE=’$getid'”,$connection),0);
$content = mysql_result(mysql_query(“SELECT content FROM persos WHERE PAGETITLE=’$getid'”, $connection),0);

$pageName = “$pagetitle”; ?>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<? echo “<title>Les Enfants de l’&Ocirc; – Personnages – ” .$title. “</title>”; ?>
<link href=”bookie.css” rel=”stylesheet” type=”text/css”>
<link href=”persos.css” rel=”stylesheet” type=”text/css”>
<script src=”dom-drag.js” language=”javascript” type=”text/javascript”></script>
</head>

<body>

<li><a href=”http://enfantsdelo.free.fr/persosphp.php?pagetitle=ruan” id=”ruan”>Ruan</a></li>
<li><a href=”http://enfantsdelo.free.fr/persosphp.php?pagetitle=ludmea” id=”ludmea”>Ludm&eacute;a</a></li>

<?php
switch ($pageName)
{
case ludmea:
$div = “ludipix”;
break;

case ruan:
$div = “ruanpix”;
break;

}

echo “<div id=”” .$div. “” title=”” .$title. “”></div>”;?>

<!– Contenu –>
<div id=”content”>
<? echo “<h1>” .$title. ” </h1>”;?>
<? echo “<p>” .$content. “</p>”;?>
</div>
// rest of the page here, but unimportant
[/code]

So, basically, the page displays information about the people (ruan and ludmea), and everything is fine. The url looks like that : [url]http://enfantsdelo.free.fr/persosphp.php?pagetitle=ruan[/url], and crazy things happen when I type in [url]http://enfantsdelo.free.fr/persosphp.php[/url]. I expected that, because there is nothing specified for that particular page (unable to jump on row 0…)… But, I would like to have a default page if people type in [url]http://enfantsdelo.free.fr/persosphp.php[/url] (cause I’m sure they will do it, just to know what happens).
How can I do that ?
Thanks a lot for your help !!!!

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@rch10007Apr 05.2006 — I would put the whole page in a if{}else{} statement so if there is no request method, they can view whatever you want then to view or redirect them if the land on the page and then the else would be the rest of the page like you have it.
[code=php]
if(!isset($_REQUEST['method'])
{
echo "Default page stuff";
}
else
{
...the page like you have it now...
}
[/code]


hope that makes sense!
Copy linkTweet thisAlerts:
@Ness_du_FratauthorApr 05.2006 — I would put the whole page in a if{}else{} statement so if there is no request method, they can view whatever you want then to view or redirect them if the land on the page and then the else would be the rest of the page like you have it.
[code=php]
if(!isset($_REQUEST['method'])
{
echo "Default page stuff";
}
else
{
...the page like you have it now...
}
[/code]


hope that makes sense![/QUOTE]

Oh, thanks a lot !!! I thought it was something like that, but I couldn't really figure it out (especially the $_REQUEST thingy)

I'll try it at once !!!

(so, I put method in the request thingy ? why is that ? (I'm still learning...))
Copy linkTweet thisAlerts:
@acemoApr 05.2006 — add to beginning:
[code=php]
<?php
if(!isset($_GET))
{
?>
~default page here~
<?php
}
else
{
?>
~current site here~
<?php
}
?>
[/code]
Copy linkTweet thisAlerts:
@Ness_du_FratauthorApr 05.2006 — I would put the whole page in a if{}else{} statement so if there is no request method, they can view whatever you want then to view or redirect them if the land on the page and then the else would be the rest of the page like you have it.
[code=php]
if(!isset($_REQUEST['method'])
{ //that's line 21
echo "Default page stuff";
}
else
{
...the page like you have it now...
}
[/code]


hope that makes sense![/QUOTE]

MM... I just tried this one, and it tells me "unexpected { on line 21", and that's all... ?
Copy linkTweet thisAlerts:
@Ness_du_FratauthorApr 05.2006 — add to beginning:
[code=php]
<?php
if(!isset($_GET))
{
?>
~default page here~
<?php
}
else
{
?>
~current site here~
<?php
}
?>
[/code]
[/QUOTE]

thanks ! I tried it, but it doesn't work either. I get the "unable to jump to row 0..."... why is that ?
Copy linkTweet thisAlerts:
@rch10007Apr 05.2006 — [code=php]
<?php

if(!isset($_GET['pagetitle']))
{
echo "Nothing to echo!";
}
else
{

// SQL database Variables
$hostname="sql.free.fr";
$user="username";
$pass="passwd";
$dbase="dbname";
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);

$getid = $_GET['pagetitle'];
$url = "http://enfantsdelo.free.fr/persosphp.php";

$pagetitle = mysql_result(mysql_query("SELECT pagetitle FROM persos WHERE PAGETITLE='$getid'",$connection),0);
$title = mysql_result(mysql_query("SELECT title FROM persos WHERE PAGETITLE='$getid'",$connection),0);
$content = mysql_result(mysql_query("SELECT content FROM persos WHERE PAGETITLE='$getid'", $connection),0);



$pageName = "$pagetitle"; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<? echo "<title>Les Enfants de l'&Ocirc; - Personnages - " .$title. "</title>"; ?>
<link href="bookie.css" rel="stylesheet" type="text/css">
<link href="persos.css" rel="stylesheet" type="text/css">
<script src="dom-drag.js" language="javascript" type="text/javascript"></script>
</head>

<body>

<li><a href="http://enfantsdelo.free.fr/persosphp.php?pagetitle=ruan" id="ruan">Ruan</a></li>
<li><a href="http://enfantsdelo.free.fr/persosphp.php?pagetitle=ludmea" id="ludmea">Ludm&eacute;a</a></li>

<?php
switch ($pageName)
{
case ludmea:
$div = "ludipix";
break;

case ruan:
$div = "ruanpix";
break;
}

echo "<div id="" .$div. "" title="" .$title. ""></div>";?>



<!-- Contenu -->
<div id="content">
<? echo "<h1>" .$title. " </h1>";?>
<? echo "<p>" .$content. "</p>";?>
</div>
// rest of the page here, but unimportant
}
?>
[/code]
Copy linkTweet thisAlerts:
@Ness_du_FratauthorApr 05.2006 — thanks a lot !!! It works perfectly !!!! I guess I made a little mistake with a {.... I really appreciate it !!! ?
Copy linkTweet thisAlerts:
@rch10007Apr 05.2006 — you're very welcome!
×

Success!

Help @Ness_du_Frat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...