rvdveen27 Posted August 4, 2015 Share Posted August 4, 2015 Hello all, I have two small questions to which I couldn't find the answer. First question: How do I create page anchors? A good example of this is wikipedia (https://en.wikipedia.org/wiki/Train). In it's contents table on the page it has several links, when clicked they scroll you down the page to the right section. Is there a way to do this in PHP and if so how? Second question: How can I edit fiels in PHP, with the current value loaded in? This is a bit of a tricky one. Basically I want it so that a user can UPDATE the fields value, however, when pressing edit, they should see the field already filled in with the information that's currently in the database. So for example: Database has a field "comments", in the comments it says "Appointment made with the user tomorrow at 3 PM". Now the user wants to update this information so he presses EDIT. He should then get to see a form/insert field, that is already filled with "Appointment made with the user tomorrow at 3 PM", which he then can add more text to, for example: "The user did not show up for the appointment". When the user then clicks submit, the full text in the database should be "Appointment made with the user tomorrow at 3 PM The user did not show up for the appointment". I hope this explanation is clear enough and I hope someone can explain me if and how this would be possible. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/297624-anchorsbookmarks-editing-fields/ Share on other sites More sharing options...
ginerjm Posted August 4, 2015 Share Posted August 4, 2015 An anchor is an html tag. That's all. So - like all html produced by a php script - you just output the anchor's contents to your page along with whatever else you want. I hope this is what you were asking because if it's anything else you didn't make it clear to me. Editing db contents using forms is one of the most basic web tasks there is. Your script begins by getting some input that identifies the record you want to update. The script takes that input (record 'key') and reads the db and then writes out the html needed to contain the form wherein you place your fields (input tags) containing the current values from the db. Now the user makes their changes and clicks a submit/edit/save changes/ etc. button. Your script gets the $_POST data from this webpage and form and handles it by validating it, ensuring that the changed data fits your db constraints (ie, a date field must contain a valid date, numeric input fields should contain only numeric values, etc.) and then prepares and executes an update query. Lastly it sends back a response to the client/user indicating that the update was successful, or it sends back the same page/form with error messages. Again - I hope this is what you were seeking. I'm surprised that you couldn't find this kind of answer in whatever research you may have already done, so I'm a little concerned that I may not understand what you are asking. 2 Quote Link to comment https://forums.phpfreaks.com/topic/297624-anchorsbookmarks-editing-fields/#findComment-1517992 Share on other sites More sharing options...
rvdveen27 Posted August 4, 2015 Author Share Posted August 4, 2015 (edited) I got the anchor thingy working now, I expected that to be fairly simple. Thanks. Now for the editing field, I don't think my explanation was all that good. I created some screenshots to clarify what I'd like to see. Now what you see are edited screenshots, I don't actually have the code working for it to do this. 1. User clicks edit. 2. User gets taken to a input field, where the current value of the "comments" field in the database is already filled in the field. 3. User adds text to the already put into place text and clicks submit. 4. Comments field is updated in the database. I hope these images clarify my explanation (I'm truly horrible at explaining things ) Edited August 4, 2015 by rvdveen27 Quote Link to comment https://forums.phpfreaks.com/topic/297624-anchorsbookmarks-editing-fields/#findComment-1517995 Share on other sites More sharing options...
Solution Barand Posted August 4, 2015 Solution Share Posted August 4, 2015 (edited) As ginerjm said, your link would be <a href = 'my_edit.php?id=9'>EDIT</a> In my_edit.php, query the database to get the current data using the id passed to it from the link SELECT comments FROM mytable WHERE id=$id Display a form with a <textarea name='comments'>$comments</textarea>, where $comments is from the database and put the id in a hidden input field. When the form is POSTed, update the database with the new comments for the same id Edited August 4, 2015 by Barand 1 Quote Link to comment https://forums.phpfreaks.com/topic/297624-anchorsbookmarks-editing-fields/#findComment-1518005 Share on other sites More sharing options...
ginerjm Posted August 4, 2015 Share Posted August 4, 2015 Your screenshots were not necessary. I understand exactly that and that is what I described in my post. As Barand also said, your anchor is wholly controlled by what you write out with you php script and your editing is done using a form and input field and a submit button as he wrote. What else do you need? Quote Link to comment https://forums.phpfreaks.com/topic/297624-anchorsbookmarks-editing-fields/#findComment-1518013 Share on other sites More sharing options...
rvdveen27 Posted August 4, 2015 Author Share Posted August 4, 2015 Thanks both of you. Both question answered and after a bit of fiddling I got it to work perfectly fine. I didn't expect my second question to be that much of a simple fix. Thanks once again for the amazing help Quote Link to comment https://forums.phpfreaks.com/topic/297624-anchorsbookmarks-editing-fields/#findComment-1518033 Share on other sites More sharing options...
rvdveen27 Posted August 6, 2015 Author Share Posted August 6, 2015 (edited) Nevermind this last reply, managed to solve my issue! Edited August 6, 2015 by rvdveen27 Quote Link to comment https://forums.phpfreaks.com/topic/297624-anchorsbookmarks-editing-fields/#findComment-1518180 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.