Jump to content

[SOLVED] Editing Posted Bulletins


Styles2304

Recommended Posts

I have a section on my church website that pulls announcements stored in mySQL and displays them with PHP. I recently started working on a control panel so that other people could login and edit/create the announcements so as to keep it up to date and lighten my load.

 

I use a while statement to display all of the bits of news but my question is how can I make an edit button specific to each row in the table on mysql? All I need to really be able to do is have an edit button spit out for each post that will set a session variable to that particular posts index number.

 

I created the mysql table with this in mind and have index numbers to reference the chunks of data.

 

Does anyone have an idea?

Link to comment
https://forums.phpfreaks.com/topic/64973-solved-editing-posted-bulletins/
Share on other sites

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 colspan="2">
        <font class="h3">
          $entrydate
        </font>
      </td>
    </tr>
    <tr>
      <td width="5">
         
      </td>
      <td width=*>
      <font class="h3">
        $data
      </font>
      </td>
    </tr>
  </table>
  
  <br><br>
  
  <form method="post" action="$indexno">
  <input type="submit" name="submit" value="Edit">

 

Am I even on the right track?

If the basic idea of this is displaying records and showing an edit button to edit each record u may have:

 

while($row = mysql_fetch_array($result)){
     $indexNo = $row['indexNo'];
     echo "<a href=\"edit.php?indexNo=$id\">Edit</a>";
}

 

Or in your specific case with the submit button:

 

<form method="post" action="<?php echo "edit.php?id=$indexNo"; ?>">
<input type="submit" name="submit" value="Edit">

 

In each case the edit button/link will point to edit.php with a respectively post/get variable which contains the id of the selected row. Hope its what u were looking for.

I'm still missing something . . .

 

since I'm using the EOD deal, I don't need to echo the link so I did this:

 

<a href="edit.php?IndexNo=$IndexNo">Edit</a>

 

Just to test to make sure $IndexNo was actually a value, I have it spit it out right next to the edit button and it works fine.

 

On the edit page . . . wouldn't I retrieve that variable with:

 

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

 

That doesn't spit anything out . . . am I missing something simple?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.