0

in my website i am fetching about.php content from database like this

$query= mysqli_query($connect,"SELECT * FROM about");
while ($row = mysqli_fetch_assoc($query)):?>
<p><?php echo $row['content']?></p>
<p><strong>Projects Completed :  </strong><?php echo  row['projects_completed']?></p>

Now there is an edit button to edit page content

<a  class="btn btn-default pull-right" href="about-us.php?edit" name="edit">Edit</a>

what i want when someone presses edit button same content should be shown in text fields and a submit button , for this should i use includes ? i mean in the beginning i include a file that fetches content and then on button click i include a file that shows content in editable mode , is that right approach ?

1 Answer 1

1

You can check for the appropriate query string (and authority to edit) and either display the content or display the content in a texture with button to submit.

if (isset($_GET['page']) && [your authority to edit check]) {
    echo '<textarea>'.$row['content'].'</textarea>';
} else {
    echo $row['content'];
}
Sign up to request clarification or add additional context in comments.

3 Comments

that seems smart let me try
are you sure this is perfect answer i mean is it good as per best practices ?
I think best practice would be to use javascript to modify the DOM and AJAX to submit changes to PHP, but in terms of an only PHP solution, I think this is pretty good. Just make sure your authority check is solid.

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.