Jump to content

$_GET


Deivas

Recommended Posts

How to find out if there is no $_GET method.

At the moment I have an if statement:

 

if($_GET['id']){
$link1 = mysql_connect("****","*****","*****");
mysql_select_db("*******", $link1);

$result1 = mysql_query("SELECT * FROM servers WHERE id = $id", $link1);
$num_rows1 = mysql_num_rows($result1);

$data = mysql_query("SELECT * FROM servers WHERE id = $id")
or die(mysql_error());

if($num_rows1 == 1){
while($info1 = mysql_fetch_array( $data ))
{
echo " 
<table border=\"1\">
<tr>
	<td><b>Name          </a></td>
	<td>" .$info1['name'] ."</td>
</tr>
<tr>
	<td><b>Type          </a></td>
	<td>" .$info1['type'] ."</td>
</tr>
<tr>
	<td><b>URL/IP:          </b></td>
	<td>" .$info1['ip'] ."</td>
</tr>
<tr>
	<td><b>Port          </b></td>
	<td>" .$info1['port']. "</td>
</tr>
<tr>
	<td><b>Description          </b></td>
	<td>" .$info1['desc']. "</td>
</tr>
</table>
<hr>
<h4>Other information</h4>
<table border=\"1\">
<tr>
	<td><b>Added by          </b></td>
	<td>" .$info1['username']. "</td>
</tr>
<tr>
	<td><b>ID          </b></td>
	<td>" .$info1['id']. "</td>
</tr>
<tr>
	<td><b>Date added (m/d/y)          </b></td>
	<td>" .$info1['date']. "</td>
</tr>
</table>

";
}
}

}

What if statement should I do for normal stuff (just for index.php (not index.php?id=324234))?

Link to comment
https://forums.phpfreaks.com/topic/194681-_get/
Share on other sites

Way to be descriptive!

 

$_GET is not a method, but a Global Array which provides access to the query string of the url. If you are getting an "index not defined" error you can do this:

 

$data = isset($_GET['data'])?$_GET['data']:'';

 

Then when you access $data, it will not throw an error. If this is not the case, please provide us with something useful, such as the "unwanted" data you are receiving.

 

Edit:

Since you actually posted something useful.

 

if (isset($_GET['id'])){

 

That will only execute if the array index of 'id' inside of $_GET has been set.

Link to comment
https://forums.phpfreaks.com/topic/194681-_get/#findComment-1023823
Share on other sites

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.