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
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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

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.