Jump to content

$_GET Function not working properly.


Mod-Jay

Recommended Posts

Okay im trying to make it so when some is on this link ("?serv=del&id=$ID") it displays a portlet of a yes/no form. onces yes/no is picked it goes to ("?serv=del&id=$ID&del=true"). I have no idea if im doing this right or if theres a better way of doing it. But trying to fix this problem has almost made me throw my computer threw my window. Thanks in advanced.

 

<?php
if(isset($_GET['serv']) && $_GET['id'] == $serverid && $_GET['del'] == 'true') {

if($_POST['ture']) {
mysql_query("DELETE FROM `notifications` WHERE `id`='$msgid'");
Echo "<center>Message Deleted</center>";
} else {
Echo "<center>Message delete request has been canceled.</center>";
}
} elseif(isset($_GET['serv']) && $_GET['id'] == $serverid) {
?>
<div class="usercp_body"><!--  UserCP Notification Manage Start -->
<div id="dash_chart" class="portlet" style="width:100%;margin: 0 auto;">
<div class="portlet-header">
	<h4><center>All Servers For <?php echo $username; ?></center></h4>
</div>
<div class="portlet-content">

<form action="manage.php?serv=del&id=<?php echo $serverid; ?>&del=true" method="post">
<input type="submit" class="bgbtn blue" value="Yes" name="true" />
<input type="submit" class="bgbtn blue" value="No" name="false" />
</form>
</div>
</div>
</div>
<?php
}
?>

Link to comment
Share on other sites

Well I see a few issues.

 

in your form you use the method as GET, but are checking the value of POST

 

If you change this

<form action="manage.php?serv=del&id=<?php echo $serverid; ?>&del=true" method="post">

to this

<form action="manage.php?serv=del&id=<?php echo $serverid; ?>&del=true" method="get">

 

Then also is this, if this rule is even needed at all........

if($_POST['ture']) {

 

Should be

if($_GET['del'] == "true") {

 

Well try those changes and see what it does.

Link to comment
Share on other sites

New code:

 

<?php
if($_GET['serv'] == "del" && $_GET['id'] == $serverid && $_GET['del'] == 'true') {

if($_GET['del'] == "true") {
mysql_query("DELETE FROM `notifications` WHERE `id`='$msgid'");
Echo "<center>Message Deleted</center>";
} else {
Echo "<center>Message delete request has been canceled.</center>";
}
} elseif($_GET['serv'] == "del" && $_GET['id'] == $serverid) {
?>
<div class="usercp_body"><!--  UserCP Notification Manage Start -->
<div id="dash_chart" class="portlet" style="width:100%;margin: 0 auto;">
<div class="portlet-header">
	<h4><center>All Servers For <?php echo $username; ?></center></h4>
</div>
<div class="portlet-content">

<form action="manage.php?serv=del&id=<?php echo $serverid; ?>&del=true" method="get">
<input type="submit" class="bgbtn blue" value="Yes" name="true" />
<input type="submit" class="bgbtn blue" value="No" name="false" />
</form>
</div>
</div>
</div>
<?php
}
?>


 

 

New code after that

 

<?php
if($_GET['serv'] == "del" && $_GET['id'] == $serverid) {
?>
<div class="usercp_body"><!--  UserCP Notification Manage Start -->
<div id="dash_chart" class="portlet" style="width:100%;margin: 0 auto;">
<div class="portlet-header">
	<h4><center>All Servers For <?php echo $username; ?></center></h4>
</div>
<div class="portlet-content">

<form action="manage.php?serv=del&id=<?php echo $serverid; ?>&del=true" method="get">
<input type="submit" class="bgbtn blue" value="Yes" name="true" />
<input type="submit" class="bgbtn blue" value="No" name="false" />
</form>
</div>
</div>
</div>
<?php
} elseif($_GET['serv'] == "del" && $_GET['id'] == $serverid && $_GET['del'] == 'true') {

if($_GET['del'] == "true") {
mysql_query("DELETE FROM `notifications` WHERE `id`='$msgid'");
Echo "<center>Message Deleted</center>";
} else {
Echo "<center>Message delete request has been canceled.</center>";
}
}
?>

Link to comment
Share on other sites

Yeah something like this

<input type="submit" class="bgbtn blue" value="Yes" name="del" />
<input type="submit" class="bgbtn blue" value="No" name="del" />

and an example of the check would be

<?php
if ($_GET['del'] == "Yes"){
echo "Was Deleted";
} else {
echo "Not Deleted";
}
?>

Link to comment
Share on other sites

Could you please help me by fixing any errors you see on this page?

 

<?php
if($_GET['serv'] == "add") {
?>
<div class="usercp_body"><!--  UserCP Notification Manage Start -->
<div id="dash_chart" class="portlet" style="width:100%;margin: 0 auto;">
<div class="portlet-header">
	<h4><center>All Servers For <?php echo $username; ?></center></h4>
</div>
<div class="portlet-content">

<form action="manage.php?serv=del&id=<?php echo $serverid; ?>&del=true" method="post">
<input type="button" class="bgbtn blue" value="Yes" name="true" />
<input type="button" class="bg-btn blue" value="No" name="false" />
</form>
</div>
</div>
<?php
}

$server_a = mysql_query('SELECT * FROM toplist WHERE userid="'. $_SESSION['id'] .'" ORDER BY id DESC') or die(mysql_error());
$serverid = 0;
if($_GET['serv'] == "manage") {
  ?>
<div class="usercp_body"><!--  UserCP Notification Manage Start -->
<div id="dash_chart" class="notifications" style="width:100%;margin: 0 auto;">
<div class="notifications-header">
	<h4><center>All Servers For <?php echo $username; ?></center></h4>
	<div class="name">
		<table border="0">
			<tr>
				<td style="width:7%;">Manage</td>
				<td style="width:7%;">Premium</td>
				<td style="width:5%;">Banned</td>
				<td style="width:20%;">Server Name</td>
				<td style="width:20%;">Server Host</td>
				<td style="width:10%;">Server Port</td>
				<td style="width:10%;">Date Made</td>
			</tr>
		</table>
	</div>
</div>
<div class="notifications-content">
<table cellspacing="0">
	<tbody>
		<?php if(mysql_num_rows($server_a) == 0) { ?>
				<tr class="table">
					<td class="name">You have not registered a server yet. <a href="index.php?serv=add">Click here</a> to register one!</td>
					<td class="revision"></td>			
					<td class="votes"></td>						
				</tr>
		<?php } else { ?>
			<?php
				While($server_b = mysql_fetch_array($server_a)) {
					$serverid = $server_b['id'];
					$servername = $server_b['servername'];
					$banned = $server_b['ban'];
					$datemade = $server_b['added'];
					$premium = $server_b['premium'];
					$serverhost = $server_b['serverhost'];
					$serverport = $server_b['serverport'];
			?>
				<tr class="table">
					<td width="7%">
						<a href="index.php?serv=del&id=<?php echo $serverid; ?>"><img src="../images/usercp/invalid.gif" /></a>    
						<a href="index.php?serv=edit&id=<?php echo $serverid; ?>"><img src="../images/usercp/edit.gif" /></a>
					</td>
					<td width="7%"><?php if($premium == 1) { echo"<font color='green'>Yes</font>"; } else { echo"<font color='red'>No</font>"; } ?></td>
					<td width="5%"><?php if(!$ban == 1){ echo "<img src=\"../images/usercp/invalid.gif\" />"; } else { echo "<img src=\"../images/usercp/unbanned.gif\" />"; } ?></td>
					<td width="20%"><a href="<?php if($premium == 1) { echo "viewserver-prem-". $serverid .".html"; } else { echo "viewserver-regular-". $serverid .".html"; } ?>"><h3><?php echo ucFirst($servername); ?></h3></td>
					<td width="20%"><h3><?php echo $serverhost; ?></h3></td>						
					<td width="10%"><h3><?php echo $serverport; ?></h3></td>						
					<td width="10%"><h3><?php echo date('m/d/Y', strtotime($datemade)) ?></h3></td>						
				</tr>
	    <?php } } ?>
	</tbody>
</table>
</div>
</div>
</div>
  <?php } ?>
  
<?php
if($_GET['serv'] == "del" && $_GET['id'] == $serverid) {
if
?>
<div class="usercp_body"><!--  UserCP Notification Manage Start -->
<div id="dash_chart" class="portlet" style="width:100%;margin: 0 auto;">
<div class="portlet-header">
	<h4><center>All Servers For <?php echo $username; ?></center></h4>
</div>
<div class="portlet-content">

<form action="manage.php?serv=del&id=<?php echo $serverid; ?>&del=true" method="get">
<input type="submit" class="bgbtn blue" value="Yes" name="true" />
<input type="submit" class="bgbtn blue" value="No" name="false" />
</form>
</div>
</div>
</div>
<?php
} elseif($_GET['serv'] == "del" && $_GET['id'] == $serverid && $_GET['del'] == 'true') {

if($_GET['del'] == "true") {
mysql_query("DELETE FROM `notifications` WHERE `id`='$msgid'");
Echo "<center>Message Deleted</center>";
} else {
Echo "<center>Message delete request has been canceled.</center>";
}
}

?>

Link to comment
Share on other sites

Heres the whole page:

 


<?php
if($_GET['serv'] == "add") {
?>
<div class="usercp_body"><!--  UserCP Notification Manage Start -->
<div id="dash_chart" class="portlet" style="width:100%;margin: 0 auto;">
<div class="portlet-header">
	<h4><center>All Servers For <?php echo $username; ?></center></h4>
</div>
<div class="portlet-content">

<form action="manage.php?serv=del&id=<?php echo $serverid; ?>&del=true" method="post">
<input type="button" class="bgbtn blue" value="Yes" name="true" />
<input type="button" class="bg-btn blue" value="No" name="false" />
</form>
</div>
</div>
<?php
}

$server_a = mysql_query('SELECT * FROM toplist WHERE userid="'. $_SESSION['id'] .'" ORDER BY id DESC') or die(mysql_error());
$serverid = 0;
if($_GET['serv'] == "manage") {
  ?>
<div class="usercp_body"><!--  UserCP Notification Manage Start -->
<div id="dash_chart" class="notifications" style="width:100%;margin: 0 auto;">
<div class="notifications-header">
	<h4><center>All Servers For <?php echo $username; ?></center></h4>
	<div class="name">
		<table border="0">
			<tr>
				<td style="width:7%;">Manage</td>
				<td style="width:7%;">Premium</td>
				<td style="width:5%;">Banned</td>
				<td style="width:20%;">Server Name</td>
				<td style="width:20%;">Server Host</td>
				<td style="width:10%;">Server Port</td>
				<td style="width:10%;">Date Made</td>
			</tr>
		</table>
	</div>
</div>
<div class="notifications-content">
<table cellspacing="0">
	<tbody>
		<?php if(mysql_num_rows($server_a) == 0) { ?>
				<tr class="table">
					<td class="name">You have not registered a server yet. <a href="index.php?serv=add">Click here</a> to register one!</td>
					<td class="revision"></td>			
					<td class="votes"></td>						
				</tr>
		<?php } else { ?>
			<?php
				While($server_b = mysql_fetch_array($server_a)) {
					$serverid = $server_b['id'];
					$servername = $server_b['servername'];
					$banned = $server_b['ban'];
					$datemade = $server_b['added'];
					$premium = $server_b['premium'];
					$serverhost = $server_b['serverhost'];
					$serverport = $server_b['serverport'];
			?>
				<tr class="table">
					<td width="7%">
						<a href="index.php?serv=del&id=<?php echo $serverid; ?>"><img src="../images/usercp/invalid.gif" /></a>    
						<a href="index.php?serv=edit&id=<?php echo $serverid; ?>"><img src="../images/usercp/edit.gif" /></a>
					</td>
					<td width="7%"><?php if($premium == 1) { echo"<font color='green'>Yes</font>"; } else { echo"<font color='red'>No</font>"; } ?></td>
					<td width="5%"><?php if(!$ban == 1){ echo "<img src=\"../images/usercp/invalid.gif\" />"; } else { echo "<img src=\"../images/usercp/unbanned.gif\" />"; } ?></td>
					<td width="20%"><a href="<?php if($premium == 1) { echo "viewserver-prem-". $serverid .".html"; } else { echo "viewserver-regular-". $serverid .".html"; } ?>"><h3><?php echo ucFirst($servername); ?></h3></td>
					<td width="20%"><h3><?php echo $serverhost; ?></h3></td>						
					<td width="10%"><h3><?php echo $serverport; ?></h3></td>						
					<td width="10%"><h3><?php echo date('m/d/Y', strtotime($datemade)) ?></h3></td>						
				</tr>
	    <?php } } ?>
	</tbody>
</table>
</div>
</div>
</div>
  <?php } ?>
  
<?php
if($_GET['serv'] == "del" && $_GET['id'] == $serverid) {
if
?>
<div class="usercp_body"><!--  UserCP Notification Manage Start -->
<div id="dash_chart" class="portlet" style="width:100%;margin: 0 auto;">
<div class="portlet-header">
	<h4><center>All Servers For <?php echo $username; ?></center></h4>
</div>
<div class="portlet-content">

<form action="manage.php?serv=del&id=<?php echo $serverid; ?>&del=true" method="get">
<input type="submit" class="bgbtn blue" value="Yes" name="true" />
<input type="submit" class="bgbtn blue" value="No" name="false" />
</form>
</div>
</div>
</div>
<?php
} elseif($_GET['serv'] == "del" && $_GET['id'] == $serverid && $_GET['del'] == 'true') {

if($_GET['del'] == "true") {
mysql_query("DELETE FROM `notifications` WHERE `id`='$msgid'");
Echo "<center>Message Deleted</center>";
} else {
Echo "<center>Message delete request has been canceled.</center>";
}
}

?>

Link to comment
Share on other sites

Don't make separate threads for the same problem.

 

Take a look at your logic: You're always going to be posting your form to manage.php?serv=del&id=&del=true because of this line:

 

<form action="manage.php?serv=del&id=<?php echo $serverid; ?>&del=true" method="post">

 

Why?  Because when your page loads, $serverid is not initialized, so it will contain a default value.  In this case, either an empty string or 0.  Your if-conditionals are failing because of this:

 

	
While($server_b = mysql_fetch_array($server_a)) {
   $serverid = $server_b['id'];
   $servername = $server_b['servername'];
   $banned = $server_b['ban'];
   $datemade = $server_b['added'];
   $premium = $server_b['premium'];
   $serverhost = $server_b['serverhost'];
   $serverport = $server_b['serverport'];
}

 

You actually have a couple things going on here:

 

1. Since you're looping over your results, $serverid will only contain the $server_b['id'] value of the last row of your result set.

2. That value likely won't be equal to $_GET['id'], which is, like I said before, either an empty string or 0 since $serverid isn't initialized when you output your form's action.

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.