Jump to content

Not Setting, Causing to redirect


Lamez

Recommended Posts

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! :D

Link to comment
Share on other sites

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.

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.