Problem of html form with multiple submit buttons
Here is my concern: I have a mini-site which allows making pages. Several users have access to my database. First: authentication, once past this page, it displays the list of existing records and according to the author of said sheets, the possible actions are not the same:
(I use real names, so I've hidden)
Here, for example, I am connected with the name D. and if I click Play, it works, I get page I want. Edit and Delete the same. But if I click on Read other lines, I always see the user D
If I switch users, the problem remains the same. Each button leads to information about the connected user. I also have an Administrator user who can normally do anything (view, edit, delete), but then he saw that the last sheet created (by the user F)
Here is the form code where there is the list:
HTML Code:
<body>
<form action="modify.php" method="post">
<table id="list">
<tr>
<th>
Title page |
</th>
<th>
Date modified |
</th>
<th>
Author of the page |
</th>
<th colspan="3">
Available actions
</th>
</tr>
<?php
$co = new PDO('mysql:host=127.0.0.1;dbname=pwet', $_SESSION['login'], $_SESSION['pwd']);
$list=$co->query("SELECT id, owner, date_redac, nom FROM page ORDER BY id ASC";);
$list->setFetchMode(PDO::FETCH_OBJ);
while($tri=$list->fetch()){
?>
<?php
$list_date = $tri->date_redac;
list($yyyy, $mm, $dd) = explode("-", $list_date);
$list_date = "$dd-$mm-$yyyy";
?>
<tr style="<?php if($user == $tri->owner){
echo "background-color: #b5e2f9;";
}else{
echo "background-color: #ff8c8c;";
}
if($user == "Administrator";){
echo "background-color: #9cff8c";
}?>">
<?php if($user == $tri->owner || $user == "Administrator";){?>
<td>
<?php echo $tri->name;?>
</td>
<td>
<?php echo $list_date;?>
</td>
<td>
<?php echo $tri->owner;?>
</td>
<td colspan="3">
<input type="hidden" name="id_select" value="<?php echo $tri->id;?>" />
<input type="submit" name="save" value="Read" />
<input type="submit" name="page_to_modify" value="Edit" />
<input type="submit" name="page_to_delete" value="Remove" />
</td>
<?php } else { ?>
<td>
<?php echo $tri->name;?>
</td>
<td>
<?php echo $list_date;?>
</td>
<td>
<?php echo $tri->owner;?>
</td>
<td colspan="3">
<input type="submit" name="save" value="Read" />
</td>
<?php
}
}
$list->closeCursor();
?>
</tr>
</table>
</form>
</body>
Normally, the id of my statement should be recovered and sent to the next page (modify.php). Is there a transformation of the type of variable to (id which is used in a mysql query to call the correct data based on the id supplied)?
I doubt that it shits in the multiple submit buttons, but I do not know how to fix it while keeping the layout and the current navigation
Any ideas?
Re: Problem of html form with multiple submit buttons
If you do a print_r($_POST); in modify.php, which variables do you see in your form?
Re: Problem of html form with multiple submit buttons
If I click on Read get: "Array ([id_select] => 74 [save] => Read)" and that, whatever the button "Read" on which I click. 74 being the id of the record written by the bilingual connected at that time. If I change my name, I see the id of the ticket he wrote.
To Change, I: Array ([id_select] => 74 [page_to_modify] => Edit).
Re: Problem of html form with multiple submit buttons
I could be wrong, but I think that one should not use form in this case, just the link with variable. (after so visually like buttons, you use <button>this spike)
Re: Problem of html form with multiple submit buttons
Your problem is that your hidden field "id_select" is duplicated as many times as you got lines in your table, so I think the browser is sending the first or last, but still the same. putting a name like "id_select []", it would, or else, "id_select" concatenated to the id for "id_select74" for example.