Distingushing between multiple buttons

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Thu Mar 06, 2003 7:02 am

Distingushing between multiple buttons

Postby Grandaddy_Low » Tue Mar 18, 2003 4:42 am

Hi all,

This is my first PHP/MySQL project so please bear with me. I think fundamentally I ain't quite got my head round posting back to the server, but here goes...

I am trying to write a page that will output the contects of a table, with an 'Update' button for each record which then takes the user to a page to update *that* record. This requires the unique ID for that row to be sent to the new page.

The table displays fine, the buttons display fine, but the update page always displays the last record.

So my question is therefore, how do I determine which button has been pressed?

Any help much appreciated. My code for that secion is below.

Cheers, G.

Code: Select all

[size=9]   print "<form method=\"post\" action=\"http://localhost/upDate.php\">";
    print "<table border=1 cellspacing=4 cellpadding=4>\n";
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
        print "\t<tr>\n";
      $set = false;
        foreach ($line as $col_value) {
            print "\t\t<td>$col_value</td>\n";
         if (!$set) {$MID = $col_value; $set = true;}
      print "<input type=\"hidden\" name=\"MID\" value=\"$MID\">";
        print "\t\t<td><input type=\"Submit\" name=\"submit\" value=\"Update\"></td>\n";
        print "\t</tr>\n";
    }//end while
    print "</table></form>\n";[/size]

User avatar
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby Redcircle » Tue Mar 18, 2003 9:56 am

I usually use a hiddden input field named something like id and have use javascript to define it with an onclick. i.e.

<input type="hidden" name="id"><input type="submit" onclick="id.value = <?php echo $line['id']; ?>" name="submit" value="submit">

Return to “mySQL & php coding”

Who is online

Users browsing this forum: Bing [Bot] and 4 guests