Lamez Posted July 24, 2008 Share Posted July 24, 2008 I have made this code below, and it is for my index page, it will allow me to edit, or delete one of my entys from the database with the correct URL. Well cmd is not setting, so I am being forced back to my index.php. here is the code: <?php ob_start(); $path = "../../"; $title = "Update Home"; include ($path."main/include/cons/head.php"); if($session->logged_in){ if($session->isAdmin()){ if(!isset($cmd)) { header('Location: '.$path.'index.php'); } if($_GET["cmd"]=="delete") { print '<h2>Topic Deleted.<h2>'; $q = "DELETE FROM `home` WHERE `id`='".$id."'"; mysql_query($q); echo '<p>'; print '<a href="'.$path.'index.php">Back to Home</a></p>'; header("Location: ".$path."index.php"); } if($_GET["cmd"]=="edit") { $r = mysql_query("SELECT * FROM `home` WHERE `id`='".$id."'"); $row = mysql_fetch_array($r); $title = $row['title']; $content = $row['content']; $id = $row['id']; print '<h2>Edit Entry</h2>'; echo '<p>'; ?> <form id="Update" name="Update" method="post" action="edit_top_act.php"> <table width="100%" border="0" bgcolor="#333333"> <tr> <td width="6%"><strong><font color="#FFFFFF">Title</font></strong></td> <td width="94%"><label> <input name="title" type="text" id="title" value="<?php echo $title; ?>" /> (<?php echo $id; ?>)</label></td> </tr> <tr> <td><strong><font color="#FFFFFF">Update</font></strong></td> <td><textarea name="update_text" id="update_text" cols="45" rows="5"><?php echo $content; ?></textarea></td> </tr> <tr> <td><input name="id" type="hidden" id="id" value="<?php echo $id; ?>" /></td> <td><label> <input type="submit" name="submit" id="submit" value="Modify" /> </label><label> <input type="reset" name="reset" id="reset" value="Reset" /> </label></td> </tr> </table> </form> <?php print '<a href="'.$path.'index.php">Back to Home</a>'; echo '</p>'; } }else{ header('Location: '.$path.'index.php'); } }else{ header('Location: '.$path.'index.php'); } include ($path."main/include/cons/foot.php"); ?> Here is my links on the index page: <?php while($row = mysql_fetch_assoc($query)) { echo "<h2>".$row['title']; if($session->logged_in){ if($session->isAdmin()){ echo " <font size='0'><a href=".$path."main/include/admin_index.php?cmd=edit&id=".$row['id'].">Edit Entry(".$row['id'].")</a></font>"; echo " <font size='0'><a href=".$path."main/include/admin_index.php?cmd=delete&id=".$row['id'].">Delete Entry(".$row['id'].")</a></font>"; } } echo "</h2><p>"; echo $row['content']; echo "<br />"; echo "</p>"; } ?> Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/116424-not-setting-causing-to-redirect/ Share on other sites More sharing options...
ranjuvs Posted July 24, 2008 Share Posted July 24, 2008 You need to get the value of cmd using $_GET or $_REQUEST global arrays $cmd = $_GET['cmd']; if(!isset($cmd)) ................ Quote Link to comment https://forums.phpfreaks.com/topic/116424-not-setting-causing-to-redirect/#findComment-598825 Share on other sites More sharing options...
wildteen88 Posted July 24, 2008 Share Posted July 24, 2008 You need to get the value of cmd using $_GET or $_REQUEST global arrays $cmd = $_GET['cmd']; if(!isset($cmd)) ................ No, that is incorrect it should be if(!isset($_GET['cmd'])) { $cmd = $_GET['cmd']; With your code isset will always return true, as $cmd already exists. remember isset checks whether a variable has been created. Quote Link to comment https://forums.phpfreaks.com/topic/116424-not-setting-causing-to-redirect/#findComment-598835 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.