Jump to content

[SOLVED] Certain variables seem to reset themselves


Styles2304

Recommended Posts

Ok this is kind of a big one and hard to explain. When you view the announcements in my control panel, it has two links Edit and delete. They both take you to the edit_announcements page but delete passes the delete variable in the url so on the edit_announcements page it handles it differently if it receives it.

 

Here's the problem:

The thing is, once you either edit or delete a variable . . . for some reason $IndexNo regardless of how many times I define it, is permanently set as "1".

 

This is completely ridiculous to me. Everytime you load the announcement page, $IndexNo is loaded correctly and then when you click on the edit or delete button, you can see in the address bar at the bottom of the screen that it is passing the correct values for $IndexNo but for some reason on the actual edit page, it ALWAYS ends up being 1.

 

Does anyone have any idea? I don't even know what code to show here lol.

 

I'll just throw some stuff down here and hope it helps.

 

 

Announcement Page:

<?php
$query = "SELECT IndexNo, EntryDate, Data FROM Announcements ORDER BY IndexNo DESC";

$result = mysql_query($query, $link)
  or die(mysql_error());
  
$announcements = ' ';

while ($row = mysql_fetch_array($result)) {
  $entrydate = $row['EntryDate'];
  $data = $row['Data'];
  $IndexNo = $row['IndexNo'];
  
  $announcements .=<<<EOD

  <table with="100%" cellpading="0" cellspacing="0" border="0">
    <tr>
      <td>
        <font class="h3">
          $entrydate
        </font>
      </td>
    </tr>
    <tr>
      <td>
      <font class="h3">
        $data
      </font>
      </td>
    </tr>
  </table>
  
  <b>
  <a href="edit_announcements.php?IndexNo=$IndexNo">Edit</a> | <a href="edit_announcements.php?IndexNo=$IndexNo&delete=y">Delete</a>
  </b>
  
  <br>
  
  <hr width="70%">
  
EOD;
  
}

echo $announcements;

?>

 

 

Part of Edit page that defines variables:

<?php

// This section gathers the info from the database and determines whether or not you have permission to view it

$query = "SELECT * FROM Announcements WHERE IndexNo = " . $IndexNo . "";

$result = mysql_query($query,$link)
  or die(mysql_error());
  
while ($row = mysql_fetch_array($result)) {
  $IndexNo = $row['IndexNo'];
  $EntryDate = $row['EntryDate'];
  $Announcement = $row['Data'];
  $OnGoing = $row['OnGoing'];
  $DelDate = $row['DeleteDate'];
  $PostBy = $row['PostBy'];
  $PAccess = $row['PublicAccess'];
//IndexNo is passed to a session variable to make deletion easier.
  $_SESSION['IndexNo'] = $IndexNo;
}

 

 

Any help at all would be hot. BTW, the rest of the variables work fine!

 

Link to comment
Share on other sites

Something else . . . every time you actually update or delete a post on the database, it uses a header to send you back to the announcements page. Again, like I said, it still seems to pass the correct variables via url but it's at that point that the problem shows up.

Link to comment
Share on other sites

On Announcements, the $IndexNo is retrieved from the database and passed to edit_announcents through url. I use $IndexNo to retrieve the information from the database for that particular post. Also, in the case of deleting, I turn $IndexNo into a $_SESSION['IndexNo'] so that it can be accessed in the delete page . . . that all works . . . but only the first time.

 

When I get home I'll post a more complete list of the code on edit_announcements.

Link to comment
Share on other sites

Ok, so here's the announcement page. This is where the announcements are displayed and you can either add a new one or choose to edit/delete an exhisting one:

 

<?php
//Connects to database using info in pass.php and designates variables
include "conn.inc.php";
include "auth.inc.php";
?>

<html>
<head>
<title>New Covenant Fellowship</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<LINK REL=StyleSheet HREF="style.css" TYPE="text/css">

</head>

<body bgcolor="#E5EFF4" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<center>
<form method="post" action="save_announcements.php">

  <table width="75%" border="0">
    <tr>
      <td width="45%" align="right" valign="top">
        Entry Date:<br>
        <font size="2pt">
        (Date Format: yyyy-mm-dd)
      </td>
      
      <td align="left" valign="top">
        <?php echo '<input type="text" size="10" maxlength="10" name="EntryDate">' ?>
      </td> 
    </tr>

    <tr>
      <td width="45%" align="right" valign="top">
        Delete Date:<br>
        <font size="2pt">
        (Date Format: yyyy-mm-dd)
      </td>
      
      <td align="left" valign="top">
        <?php echo '<input type="text" size="10" maxlength="10" name="DeleteDate">' ?>
      </td>
    </tr>
    
    <tr>
      <td width="45%" align="right" valign="top">
        On Going? (Input Y or N in caps)
      </td>
      <td align="left" valign="top">
        <?php echo '<input type="text" size = "1" maxlength="1" name="OnGoing">'?>
      </td>
    </tr>
    
    <tr>
      <td width="45%" align="right" valign="top">
        Public Access? (Input Y or N in caps):
      </td>
      
      <td align="left" valign="top">
        <?php echo '<input type="text" size = "1" maxlength="1" name="PAccess">'?>
      </td>
    </tr>
    
    <tr>
      <td width="100%" colspan="2" valign="top" align="center">
        <?php echo '<textarea rows="10" cols="50" name="Announcement" wrap="soft"></textarea>' ?>
      </td>
    </tr>
  </table>
  
  <input type="submit" name="submit" value="Save">
</form>


<table width="90%">
<td>
<?php
$query = "SELECT IndexNo, EntryDate, Data FROM Announcements ORDER BY IndexNo DESC";

$result = mysql_query($query, $link)
  or die(mysql_error());
  
$announcements = ' ';

while ($row = mysql_fetch_array($result)) {
  $entrydate = $row['EntryDate'];
  $data = $row['Data'];
  $IndexNo = $row['IndexNo'];
  
  $announcements .=<<<EOD

  <table with="100%" cellpading="0" cellspacing="0" border="0">
    <tr>
      <td>
        <font class="h3">
          $entrydate
        </font>
      </td>
    </tr>
    <tr>
      <td>
      <font class="h3">
        $data
      </font>
      </td>
    </tr>
  </table>
  
  <b>
  <a href="edit_announcements.php?IndexNo=$IndexNo">Edit</a> | <a href="edit_announcements.php?IndexNo=$IndexNo&delete=y">Delete</a>
  </b>
  
  <br>
  
  <hr width="70%">
  
EOD;
  
}

echo $announcements;

?>
</td>
</table>

</center>
</body>
</html>

 

When you click edit . . . it goes to the edit_announcements page:

 

<?php
include "auth.inc.php";
include "conn.inc.php";
?>

<html>
<head>
<title>Website Template</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<LINK REL=StyleSheet HREF="style.css" TYPE="text/css">

</head>


<body bgcolor="#E5EFF4" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<center>

<?php

// This section gathers the info from the database and determines whether or not you have permission to view it

$query = "SELECT * FROM Announcements WHERE IndexNo = " . $IndexNo . "";

$result = mysql_query($query,$link)
  or die(mysql_error());
  
while ($row = mysql_fetch_array($result)) {
  $IndexNo = $row['IndexNo'];
  $EntryDate = $row['EntryDate'];
  $Announcement = $row['Data'];
  $OnGoing = $row['OnGoing'];
  $DelDate = $row['DeleteDate'];
  $PostBy = $row['PostBy'];
  $PAccess = $row['PublicAccess'];
  $_SESSION['IndexNo'] = $IndexNo;
}

if ($PostBy != $_SESSION['user_logged'] AND $PAccess != 'Y') {
  
?>

<br>

<hr width="100%">
Edit Announcements
<br>
<hr width="100%">

<br>

Sorry, you don't have permission to edit this Announcement. The Announcement was posted by someone else
and was not marked public.

</center>
</font>
</body>
</html>



<?php
// This section handles incoming traffic of "Delete" posts.

} else {

if ($delete == 'y') {
?>

<br>

<hr width="100%">
Delete Announcements
<br>
<hr width="100%">

<br>

Are you sure you want to delete this Announcement?<br>

<?php
echo $IndexNo;
echo $_SESSION['IndexNo'];
?>

<br>
<b>
<a href="delete_announcements.php">Yes</a> | <a href="announcements.php">No</a>
</b>


</center>
</font>
</body>
</html>

<?php
// This section handles incoming traffic of "Edit" posts.

} else {
?>

<br>

<hr width="100%">
Edit Announcements
<br>
<hr width="100%">

<br>

<form method="post" action="update_announcements.php">

<input type="hidden" name="IndexNo" value="<?php echo $IndexNo; ?>">

  <table width="75%" border="0">
    <tr>
      <td width="45%" align="right" valign="top">
        Entry Date:<br>
        <font size="2pt">
        (Update Date if major changes are made to the body of the message.)
      </td>
      
      <td align="left" valign="top">
        <?php echo '<input type="text" size="10" maxlength="10" name="EntryDate" value="'.$EntryDate.'">' ?>
      </td> 
    </tr>

    <tr>
      <td width="45%" align="right" valign="top">
        Delete Date:<br>
        <font size="2pt">
        (If no delete date is present, message will be deleted 2 weeks from Entry Date.)
      </td>
      
      <td align="left" valign="top">
        <?php echo '<input type="text" size="10" maxlength="10" name="DeleteDate" value="'.$DelDate.'">' ?>
      </td>
    </tr>
    
    <tr>
      <td width="45%" align="right" valign="top">
        On Going? (Input Y or N in caps)
      </td>
      <td align="left" valign="top">
        <?php echo '<input type="text" size = "1" maxlength="1" name="OnGoing" value="'.$OnGoing.'">'?>
      </td>
    </tr>
    
    <tr>
      <td width="45%" align="right" valign="top">
        Public Access? (Input Y or N in caps):
      </td>
      
      <td align="left" valign="top">
        <?php echo '<input type="text" size = "1" maxlength="1" name="PAccess" value="'.$PAccess.'">'?>
      </td>
    </tr>
    
    <tr>
      <td width="100%" colspan="2" valign="top" align="center">
        <?php echo '<textarea rows="10" cols="50" name="Announcement" wrap="soft">'.$Announcement.'</textarea>' ?>
      </td>
    </tr>
  </table>
  
  <input type="submit" name="submit" value="Save">
</form>



</center>
</font>
</body>
</html>

<?php
}
}
?>

 

And, as you can see, when you edit one, it fires update_announcements.php:

 

<?php
include "auth.inc.php";
include "conn.inc.php";

//Defines variables
$IndexNo = $_POST['IndexNo'];
$EntryDate = $_POST['EntryDate'];
$DelDate = $_POST['DeleteDate'];
$OnGoing = $_POST['OnGoing'];
$PAccess = $_POST['PAccess'];
$Announcement = $_POST['Announcement'];

//Sets up new query to enter variables into database
$query = "UPDATE Announcements SET " .
         "EntryDate = '" . $EntryDate . "', " . 
         "Data = '" . $Announcement . "', " . 
         "OnGoing = '" . $OnGoing . "', " . 
         "DeleteDate = '" . $DelDate . "', " . 
         "PostBy = '" . $_SESSION['user_logged'] . "', " . 
         "PublicAccess = '" . $PAccess . "' WHERE IndexNo = " . 
         $IndexNo . "";

mysql_query($query,$link)
  or die(mysql_error());
  
header('Location: announcements.php');
?>

 

Like I said earlier, once you run through this either editing OR deleting, $IndexNo will return 1 on all the pages (except the initial announcements page) regardless of what announcement you choose.

Link to comment
Share on other sites

Sorry, I didn't even notice that line where it was outputting the $IndexNo.

 

When you retrieve it on the edit page you need to use the $_GET array.

$query = "SELECT * FROM Announcements WHERE IndexNo = " . $_GET['IndexNo'] . "";

 

That should fix it.

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.