iLuke Posted January 30, 2009 Share Posted January 30, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/143184-solved-very-simple-form-question/ Share on other sites More sharing options...
iLuke Posted January 31, 2009 Author Share Posted January 31, 2009 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/143184-solved-very-simple-form-question/#findComment-751252 Share on other sites More sharing options...
iLuke Posted February 1, 2009 Author Share Posted February 1, 2009 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/143184-solved-very-simple-form-question/#findComment-751960 Share on other sites More sharing options...
Snart Posted February 1, 2009 Share Posted February 1, 2009 Why not removing the Delete again with a substr() after the form is submitted? Personally, I would also work with a hidden field which stores the ID of the user, and not extract the user from the delete value. Quote Link to comment https://forums.phpfreaks.com/topic/143184-solved-very-simple-form-question/#findComment-751963 Share on other sites More sharing options...
iLuke Posted February 1, 2009 Author Share Posted February 1, 2009 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 =[) Quote Link to comment https://forums.phpfreaks.com/topic/143184-solved-very-simple-form-question/#findComment-752053 Share on other sites More sharing options...
Snart Posted February 1, 2009 Share Posted February 1, 2009 That's the way I understood it. Can you post the GET function here? Quote Link to comment https://forums.phpfreaks.com/topic/143184-solved-very-simple-form-question/#findComment-752057 Share on other sites More sharing options...
iLuke Posted February 1, 2009 Author Share Posted February 1, 2009 <?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: http://www.privatepie.com/admin/manageuser.php?delete=Test 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. Quote Link to comment https://forums.phpfreaks.com/topic/143184-solved-very-simple-form-question/#findComment-752108 Share on other sites More sharing options...
revraz Posted February 1, 2009 Share Posted February 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/143184-solved-very-simple-form-question/#findComment-752112 Share on other sites More sharing options...
iLuke Posted February 1, 2009 Author Share Posted February 1, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/143184-solved-very-simple-form-question/#findComment-752134 Share on other sites More sharing options...
revraz Posted February 1, 2009 Share Posted February 1, 2009 I would highly recommend you set a ID for each user as well in the DB. Quote Link to comment https://forums.phpfreaks.com/topic/143184-solved-very-simple-form-question/#findComment-752140 Share on other sites More sharing options...
iLuke Posted February 1, 2009 Author Share Posted February 1, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/143184-solved-very-simple-form-question/#findComment-752202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.