Jump to content

Recommended Posts

Hey all.
Im slightly new to PHP and MYSQL so sorry if my code is a mess and has "odd ways" of doing things.
But it works for me so far and thats all that matter really isnt it?

Anyway I have a php script that generates a table of information.
What i would like is a Edit button for each row of that table so when pressed it will open a new page with a form where the user can update the fields for that entry.

 

I have messed around a little bit with ideas i know from my limited HTML and PHP but can't seem to get it to work
and not sure what to put when i google it so I cant seem to find a solution anywhere

Currently it is sending the last ID that it loads into the table no matter what edit button you press.

 

Here is my current code

echo "<table border='1'>";
echo "<tr> <th>Edit</th> <th>CardID</th> <th>Location</th> <th>Date Placed</th> <th>Found</th> <th>Date Found</th> <th>Found By</th> </tr>";
while($row = mysql_fetch_array($cards)) {
echo "<tr><td>"; 
$cardID = $row['MemberCode'] . $row['CardID'];
echo "<form action='../editcard.php' method='POST'>";
echo "<input type='hidden' name='CardID' value='";
echo $CardID;
echo "'>";
echo "<input type='Submit' value='Edit'>";
echo "</td><td>"; 
echo $CardID;
echo "</td><td>"; 
echo $row['Location'];
echo "</td><td>";
echo $row['DatePlaced'];
echo "</td><td>"; 
$found = $row['Found'];
if ($found == 1)
{
echo "yes";
}
else
{
echo "no";
}
echo "</td><td>";
echo $row['DateFound'];
echo "</td><td>";
echo $row['FoundBy'];
echo "</td></tr>"; 
} 
echo "</table>";

Thanks for any help in advance

Link to comment
https://forums.phpfreaks.com/topic/282028-help-with-edit-entry-button/
Share on other sites

your not closing your form off after each loop. the </form> is missing. so you have ended up with a load of inputs with the same name (cardID) . php will be passed the last one in the form with that name

Ah is it something really that stupidly simple. I swear both my and my friend looked over this code so many times trying to figure this out.

I shall try it now and let you know.

Thanks for the help btw.

 

(How did I miss that?)

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.