Jump to content

Recommended Posts

Hi.

 

I am currently working on an admin section for my site.

Presently it'll list all users and their details on the page nicely, but obviously that's not much of an admin section lol

I have two buttons under each 'record' - Edit and Delete.

 

Using the $_GET method, I am sending the following information: (depending on which button is clicked)

edituser.php?edit=USERHERE

edituser.php?delete=USERHERE

 

I've put in a two test if statements to check whether the browser can tell which method was sent.. E.g. do I wanna delete the user or just edit them.. that works fine.

 

Here is the code for the buttons, and the problem:

<input type="submit" name="edit" class="button" value="' . $username . '"></input>
<input type="submit" name="delete" class="button" value="' . $username . '"></input>

The text that shows up on the buttons is obviously just the username and that has to be the case because if I were to do:

<input type="submit" name="delete" class="button" value="Delete' . $username . '"></input>
then the value returned by the get would be:

edituser.php?delete=Delete+USERHERE

Which I assume would break it.

 

What I am asking then is can I display the text "Delete USERHERE" or "Edit USERHERE" but only send

edituser.php?edit=USERHERE OR edituser.php?delete=USERHERE

via the GET method?

 

(single quotes are because it's part of a bigger echo that includes the main part of the data and styling)

Thanks, Luke

Link to comment
https://forums.phpfreaks.com/topic/143184-solved-very-simple-form-question/
Share on other sites

Hehe I'm  just a beginner so I don't really understand that.

 

I don't think I explained what the problem was too well, though.

 

On the buttons it says the users name, instead of what the action of clicking the button does and I dunno how to get the button to say "Delete USER" instead of just "USER" without messing up the GET function ('cos the URL would then say edituser.php?delete=Delete+USER =[)

<?php 
if ($_GET['edit']) {
echo ("<h1>Edit " . $_GET['edit'] . "'s details:</h1><br />");
}
elseif ($_GET['delete']) {
echo ("Clicking the button below will <b>permenantly delete " . $_GET['delete'] . "</b>s details.<br />
Please be sure before you click the below button!<br /><br />");
echo ('<form name="verify" action="deleteuser.php" method="get">
		<i>(This action cannot be undone!!)</i><br /><br />
		<input type="submit" name="delete" class="button" value="' . $_GET['delete'] . '"></input>
		</form>');
}
?>

 

This isn't finished yet obviously, but it's what the page is running when it is first loaded up. The url could be:

If you click the button that sends the delete information using GET to the page with the above code on it. But on the index.php file for the admin folder, the buttons just say "Test" (which is right, because they're coded that way) but I can't work out how to make them say "Delete Test" or "Edit Test" without it messing up the url (and therefore the code above).

 

I imagine it's a silly thing that is really easy when you know how but I'm only a newbie =] - PHP is pretty tricky, and it's certainly not straight forward hehe.

I think you are going about this incorrectly.  Instead of using a form, just use a URL.  So for each user, just have a url next to them with Edit and another for Delete.  Then for each one, just pass the ID of the user, ie

 

<a href="www.mysite.com/page.php?edit=<?php echo $id;?>">Edit</a>

or

echo "<a href='www.mysite.com/page.php?edit=$id'>Edit</a>";

 

And just set the ID in a session when they log in.

Ahh! I tried to get their username to be a link... but didn't have a clue how to do it. I was trying to get the action="" function into a a href lol... guess I was barking up the wrong tree!

 

I'll try your idea mate. I think I would be able to call use the same variable that is pulled from the database using SQL, so instead of ID it'd be $username or whatever =]

 

I imaigne then, instead of having a page structure like this:

index

-- manage users.php

---- delete

---- edit

 

I'd just have delete.php and edit.php. That'll be a lot more efficient! Cheers for the help... apologies for my atrocious explaining lol!

 

Thanks again for your time guys!!

Luke

I do have an ID for the users in the DB, but I just use the username for everything to do with sessions at the minute because it makes it easier for me to see when something is working or not... like I can echo out $_SESSION['username'] to see whether or not the right data is held there. I will move on to using ID's when I get a bit more confident in my coding abilities. I imagine that they're more secure?

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.