2
Contributors
5
Replies
39
Views
2 Years
Discussion Span
Last Post by diafol
0

Add a class to your delete button (link), e.g.

class="delete-button"

But as you are not referencing your delete buttons to a row id in any way, you need to do that somehow. One way would be to add a data-id attribute to the button/link:

data-id="<?=row['userID']?>"

Also add and id to the modal userID field. Adding a default userID as a value to the modal makes no sense.

<input name="userID" id="userID" type="hidden" value="" />

Also not sure why you're doing a

deleteuser<?php echo $row['userID']; ?>

I have the sinking feeling that you've added a modal for every record. If this is NOT the case, then I can't understand the need to pass php values to the modal div block.

Add a handler - assuming using jQuery aas you're using Bootstrap:

$('.delete-button').click(function()
{
    //your inline data-toggle should open the modal
    //so no need to replicate that code here

    //this passes the id from the delete button to the hidden field:
    $('#userID').val($(this).data('id'));

});

But, your modal form has no action.

 <form action="" method="post">

You should never send a form to itself (own page) if you can avoid it. All forms data should be sent to a "handler" of some description and then depending on the processing, the handler redirects either to the same page or to another, with or without an error/success message.

At least you used POST instead of GET.

PS. Why using a link (<a>) for the delete buttons in your table instead of an action button (<button>) ?

0

Hello diafol,

Thank you and highly appreciated your response. When I click the view buttom, the user profile open and work fine. I'm using the follwing code to do this:

echo '<td><a href="index.php?action=viewuser&userID=' . $row['userID'] . '"><i class="fa fa-edit text-info" data-toggle="tooltip" data-placement="left" title="View User"></i></a>

When I try to use the same procedure for delete a user using modal i got error becuase the UserID in this case is not defined:

   <a data-toggle="modal" href="#deleteuser<?php echo $row['userID']; ?>"><i class="fa fa-trash-o text-danger" data-toggle="tooltip" data-placement="left" title="Delete"></i></a> 
    echo "</tr>";

The error message:
Parse error: syntax error, unexpected 'userID' (T_STRING), expecting ',' or ';'

So the main problem with using the table fields.

Best regards.

0

Forgive me for saying so, but this HTML, PHP mish-mash is a bit of a car crash. Usually, try to separate HTML and PHP as much as possible.
Generally we try to hide away as much code as possible in include files or at least place the functional stuff above the DTD. Markup should only contain minimal PHP, such as 'echo', the odd 'loop' and 'conditional'.

Your problem is here:

echo '<td><a href="index.php?action=viewuser&userID=' . $row['userID'] . '"><i class="fa fa-edit text-info" data-toggle="tooltip" data-placement="left" title="View User"></i></a>
<a href="#deleteuser" data-toggle="modal"><i class="fa fa-trash-o text-danger" data-toggle="tooltip" data-placement="left" title="Delete"></i></a> 
    echo "</tr>";

You have echoed inside an echo:

echo '<td><a href="index.php?action=viewuser&userID=' . $row['userID'] . '"><i class="fa fa-edit text-info" data-toggle="tooltip" data-placement="left" title="View User"></i></a>
<a href="#deleteuser" data-toggle="modal"><i class="fa fa-trash-o text-danger" data-toggle="tooltip" data-placement="left" title="Delete"></i></a>'; 
echo "</tr>";

Should fix it.

However, do consider changing all this echoed markup - it will be extremely difficult to modify. Maintenance nightmare.

0

Hello diafol,
Your solution does not work. I explain that my code working fine. All what i need is how to send the userId to modal to confirm the deletion. I try this, but got error on using <?php echo $row['userID']

<a a data-toggle="modal" href="#deleteuser<?php echo $row['userID']; ?>"><i class="fa fa-history text-success" data-toggle="tooltip" data-placement="left" title="Delete"></i></a>

I think because I'm using <?php within the php.

Now when using

<a data-toggle="modal" href="#deleteuser'.$row['userID'].' ">i class="fa fa-history text-success" data-toggle="tooltip" data-placement="left" title="Delete"></i></a>

I can get the userID but can't open the modal.

Any solution.

Thanks.

0

Your solution does not work.

Heh heh.

If you're telling me that your original is valid code...

echo '<td><a href="index.php?action=viewuser&userID=' . $row['userID'] . '"><i class="fa fa-edit text-info" data-toggle="tooltip" data-placement="left" title="View User"></i></a>
<a href="#deleteuser" data-toggle="modal"><i class="fa fa-trash-o text-danger" data-toggle="tooltip" data-placement="left" title="Delete"></i></a> 
    echo "</tr>";

... one of us has spent too long in the sun.

Anyhow, I'm not suggesting that was your ONLY problem, but the one that was causing your last error message.
I know I'm gonna regret this... can you show your latest code snippet please.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.