Jump to content

Update ID


dino2dy

Recommended Posts

I created a page that lists all the rows from my database in a list in a web page. Next to each of the rows are edit and delete buttons. I want the user to be able to edit the row for which the edit button is clicked. The web page has no login so no session is started, I had looked for awhile around the web, and saw that there might be a way to store the ID from the row into a cookie but im not sure how to do that. I just can't figure out how to save the ID of a particular row that is clicked on and then use it to identify the row that needs to be edited or deleted.

Here's the php code for the page that prints out all the rows from a database and the edit buttons next to em.

<?php
   $query = "SELECT * FROM komitenti";


if ( !( $database = mysql_connect( "localhost", "root", "pokemon" ) ) )                      
                die( "Could not connect to database </body></html>" );
           // open Products database
              if ( !mysql_select_db( "dino", $database ) )
                die( "Could not open register database </body></html>" );

   if ( !( $result = mysql_query( $query, $database ) ) ) 
         {
            print( "Could not execute query! <br />" );
            die( mysql_error() . "</body></html>" );
         } // end if

    // fetch each record in result set
   for ( $counter = 0; $row = mysql_fetch_row( $result ); $counter++ )
   {
    // build table to display results
print( "<tr style= border-color:#00FF00;>" );

foreach ( $row as $key => $value ) 
print( "<td style= border-color:#00FF00>$value </td><td style= border-color:#00FF00;><a href=\"EditKomitent2.php\">EDIT</a></td>");

print( "</tr>" );
} // end for
         mysql_close( $database );
    ?><!-- end PHP script -->    </td>

 

I already created a web page with a form for inserting a new row which works, and I figure I can use the same form for editing an already existing rows as all the fields are the same Ill just save it under a different name change the SQL from Insert Into to Update and link to it. But how do I identify the row it's supposed to edit?

 

I am really at my wits end, I tried to do it myself failed, tried searching online but all of the things I ran into were so complicated. I tried accomodating some stuff to suit the online things but I couldn't do it. So any help would be really appreciated.

Link to comment
https://forums.phpfreaks.com/topic/164304-update-id/
Share on other sites

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.