-4

My Question is. How can i create an button to edit my profile ? After I click a Save button or something like that it should overwrite the information in the DB.

Thats my HTML Code:

<div>      
     <section class='container_profile'>
         <h1>Profil</h1>
         <h2>Username:</h2> <p><?php echo $username; ?></p>
         <h2>Password:</h2> <p>*******</p>
         <h2>Lohn 1.Lehrjahr:</h2> <p><?php echo $salary_first_year; ?></p>
         <h2>Lohn 2.Lehrjahr:</h2> <p><?php echo $salary_second_year; ?></p>
         <h2>Lohn 3.Lehrjahr:</h2> <p><?php echo $salary_third_year; ?></p>
         <h2>Lohn 4.Lehrjahr:</h2> <p><?php echo $salary_fourth_year; ?></p>
         <button class="btn_edit" onclick="">EDIT</button>

    </div>

It should appear textboxes when I click on the button.

j.walt
  • 11
  • 3
  • 6
    your buttons is already on the place, it's at the bottom of your code ``. Just bind corresponding `onclick` event, and you are fully done. – Farside May 11 '16 at 09:19
  • Don't know how i should code this onclick event. – j.walt May 11 '16 at 09:20
  • As farside stated thats what you should do, but do you know javascript? I see your tag has php and html so you want to perform this specifically with php? – izk May 11 '16 at 09:22
  • @j.walt you need to handle it with javascript or with PHP. Just learn some basics. – Jehy May 11 '16 at 09:22
  • J.Walt, neither do I. It's totally up to you how to code this logic, and what it should contain. You may read a bit of [information here](http://stackoverflow.com/questions/1525664/jquery-how-to-bind-onclick-event-to-dynamically-added-html-element) or at other answers. You are asking about very basic things in JS. – Farside May 11 '16 at 09:23
  • 1
    I want to perform this just with php, no javascript. – j.walt May 11 '16 at 09:23
  • can you please edit your question to give more information and what do you want with the information? Stored in DB or simply echo on screen? And what did you try so far with **php** to make it succeed – izk May 11 '16 at 09:28
  • @j.walt, find [my answer](http://stackoverflow.com/a/37158378/4354249) below. it contains some references you need to read first, before asking really trivial, basic things. – Farside May 11 '16 at 09:28
  • 2
    Then you need to deal with a page reload. You could create a link to another view, which would be your edit view... Edit on that page you can display the whole user content in input fields and edit them – noa-dev May 11 '16 at 09:28
  • @noa-dev, you advice is not really good. because with href - the form contents would be lost, it simply would redirect the guy to your URL. Find out my answer with the form submit below. – Farside May 11 '16 at 09:29
  • @Farside I would expect to print out the user data on the edit page as well, so actually no information would be lost. If he wants to do everything in PHP he wont come around a page reload which either would result in a new query request to fetch data OR to read data from stored session variables – noa-dev May 11 '16 at 09:31

2 Answers2

2

There are two ways to proceed for you, and both would require reading and learning, as it seems you gotten really basic knowledge how PHP works and how JS works.

  1. you may create the simple form, with submit button, which will submit to PHP handler and will reload the page.
  2. You can write JavaScript handler onclick, and to bind it to your button, and it will do the job via AJAX call, without reloading of page.

Hope this helps you start with some education first. Start here => PHP Manual: Dealing with Forms

Farside
  • 9,923
  • 4
  • 47
  • 60
-1

You could have your profile displayed in a span with editable false. Then when you click the button it can check user creds on the db and set editable true. Next you will need a save button where the user can update the profile vale that was initially displayed in the span.

More specifically and less dangerously you can have a button to upload a new profile image or something like that...alternatively you could hit the edit button and change all the displayed values to input fields. There really are a lot of way's to go about it, what specifically have you tried so far in php?

if (userAuth && UserEditProfile){
    echo editablePage;
}else{
    echo profile;
}

enter image description here

kpie
  • 9,588
  • 5
  • 28
  • 50
  • That was kind of my idea. but I dont know exactly how this could be done. How can i change the displayed values to input fields ? – j.walt May 11 '16 at 09:29
  • You can check user credentials against a database and then redirect to a supplementary page that has the display fields replaced with handles. – kpie May 11 '16 at 13:00