2

I have a a page where users create and account and edit password if the account already exists. I'm using php - codeigniter

When users update passwords, the input field currently allows them to change their username as well as their password. I'm trying to make it so that users can only update passwords and not usernames but I have had trouble doing so.

This is my code

<input required type="text" 
placeholder="page name" 
value="<?= $form_value['name'] ?>" name="name" id="name">

I am trying to make it so that the username is printed but it is not updated.

The only thing I can think of is making the input type hidden (as shown in the below code), but then users can minipulate it and change it in the inspect element option of the browser and update their users.

<input required type="hidden" placeholder="page name" value="<?= $form_value['name'] ?>" name="name" id="name">

I am not sure what to do, Thanks in advance

3 Answers 3

2

use should echo your php variable to get its value inside your html input element

<input required type="text" placeholder="page name" value="<?= echo $form_value['name']; ?>" name="name" id="name">

in the above syntax you are using php shorthand syntax, so you should enable it first. you can use like this also without short tags

<input required type="text" placeholder="page name" value="<?php echo $form_value['name']; ?>" name="name" id="name">
Sign up to request clarification or add additional context in comments.

2 Comments

might wanna change <?= to <?php as <?= is a shorthand to echo a statement
@ThisGuyHasTwoThumbs yes he used shorthand syntax of php, i edited my answer
1

I assume you're using a database to store this information. If that is the case - just don't update the username field when you are updating the password. There are many cases where the user could go into inspect element and change things, but all that matters is what you're doing on the back-end.

Comments

0

Just echo the plain username without input field (if user is logged in) & empty input field (for new user registration), while update take the user_id from session & update the respective password of the logged in user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.