Jump to content

[SOLVED] default $_GET value?


lilwing

Recommended Posts

I am using $_GET values to create dynamic links. The variable is called $pageid. Obviously, when a user types the URL into his/her browser, the $_GET value is not set.

 

In order to display the content on the homepage, I need $pageid = 'home'

 

How can I set up a default value for $pageid?

 


		<?php

$pageid= $_GET['pageid'];

$query = mysql_query("SELECT Content FROM sfiscontent WHERE ContentID='$pageid'") or die(mysql_error());
while($row = mysql_fetch_array($query)) {
$current = $row['Content'];
echo $current;

}		
		?>

Link to comment
https://forums.phpfreaks.com/topic/115309-solved-default-_get-value/
Share on other sites

isset() is your friend. You also wouldn't want to be querying the database without validating your input.

 

if(isset($_GET['pageid'])){
$pageid = mysql_real_escape_string($_GET['pageid']);//ought to be sanitizing your input.
}else{
$pageid = 'home';
}

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.