Jump to content

Anchors/bookmarks & editing fields.


rvdveen27
Go to solution Solved by Barand,

Recommended Posts

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! :)

Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

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. 0LvBBqh.jpg

 

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. meJjzq2.jpg

 

3. User adds text to the already put into place text and clicks submit. KOjyRoT.png

 

4. Comments field is updated in the database. 0k5l2Ge.png

 

I hope these images clarify my explanation (I'm truly horrible at explaining things :P)

Edited by rvdveen27
Link to comment
Share on other sites

  • Solution

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 by Barand
  • Like 1
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.