Mod-Jay Posted April 12, 2011 Share Posted April 12, 2011 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/ Share on other sites More sharing options...
QuickOldCar Posted April 12, 2011 Share Posted April 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200350 Share on other sites More sharing options...
Mod-Jay Posted April 12, 2011 Author Share Posted April 12, 2011 Nothing happened Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200351 Share on other sites More sharing options...
Mod-Jay Posted April 12, 2011 Author Share Posted April 12, 2011 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>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200353 Share on other sites More sharing options...
btherl Posted April 12, 2011 Share Posted April 12, 2011 You have one submit button named "true" and another named "false". You should find the respective values in $_GET['true'] and $_GET['false']. Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200361 Share on other sites More sharing options...
KevinM1 Posted April 12, 2011 Share Posted April 12, 2011 Where's $serverid coming from? Is its value set anywhere upon page refresh? Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200364 Share on other sites More sharing options...
QuickOldCar Posted April 12, 2011 Share Posted April 12, 2011 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200366 Share on other sites More sharing options...
Mod-Jay Posted April 12, 2011 Author Share Posted April 12, 2011 Its not the code!!?! its the way getting to the code. $_GET['serv'] = "del" && id=$serverid ISNT WORKING Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200376 Share on other sites More sharing options...
Mod-Jay Posted April 12, 2011 Author Share Posted April 12, 2011 Please help -____- Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200791 Share on other sites More sharing options...
KevinM1 Posted April 12, 2011 Share Posted April 12, 2011 Again, where is $serverid coming from? It's not a value coming from your form, so where are you initializing it? Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200795 Share on other sites More sharing options...
Mod-Jay Posted April 12, 2011 Author Share Posted April 12, 2011 A while( ) loops above it displaying table settings. Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200811 Share on other sites More sharing options...
KevinM1 Posted April 12, 2011 Share Posted April 12, 2011 Can you show that code? $serverid is a key part of your conditional statements. If it's not being set properly, then nothing will show. Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200819 Share on other sites More sharing options...
Mod-Jay Posted April 12, 2011 Author Share Posted April 12, 2011 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>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200823 Share on other sites More sharing options...
Mod-Jay Posted April 12, 2011 Author Share Posted April 12, 2011 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>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200824 Share on other sites More sharing options...
KevinM1 Posted April 12, 2011 Share Posted April 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200832 Share on other sites More sharing options...
Mod-Jay Posted April 12, 2011 Author Share Posted April 12, 2011 Thanks for trying everyone, but i fixed the error. Quote Link to comment https://forums.phpfreaks.com/topic/233436-_get-function-not-working-properly/#findComment-1200857 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.