Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9169717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:55:02+00:00 2026-06-17T15:55:02+00:00

I am having a php form, and a lot of markup, so i need

  • 0

I am having a php form, and a lot of markup, so i need to repeat the same form for creating a new page entry and same for editing, so for example what am doing right now is

if($_GET['page'] == 'hello') {
   //A whole lot of markup goes here
   <form method="post">
     <input type="text" name="whatever" />
     <input type="submit" name="create_new" />
   </form>
} elseif ($_GET['page'] == 'edit_hello') {
   //Same form markup is here, only change is the retrieved 
   //data values are echo'ed out in respective fields
   $query = mysqli_fetch_array(mysqli_query(...));
   <form method="post">
     <input type="text" name="whatever" value="<?php echo $query['column_name']; ?>" />
     <input type="submit" name="create_new" />
   </form>
}

So any idea how can I use the same code for creating new entry as well as updating the form values

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:55:03+00:00Added an answer on June 17, 2026 at 3:55 pm

    Use a variable and give it a default value of an empty string.

    if($_GET['page'] == 'hello') {
       $whatever = "";
    } elseif ($_GET['page'] == 'edit_hello') {
       $query = mysqli_fetch_array(mysqli_query(...));
       $whatever = $query['column_name'];
    }
    
    <form method="post">
       <input type="text" name="whatever"
          value="<?php echo htmlspecialchars($whatever); ?>" />
       <input type="submit" name="create_new" />
    </form>
    

    Note that I’ve also added proper escaping for you, so that you can avoid XSS attacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems removing index.php from codeigniter-2. I remember using the same code
Hello everyone I been trying get php uploader working but having a lot of
I'm having a little problem with form submission with jquery. I've submitted a lot
I'm having an array of data in PHP. It is a lot of data
I am having some trouble with a PHP contact form, when submitted this form
I'm having trouble with my php form that i query the info from the
I'm having some difficulties with the php form concept which is as follows: There
I'm having issues getting a php form to write to a file hosted with
Is it possible to to have a PHP form without having a seperate file,
I'm having a problem using a CSV file uploaded via a PHP form. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.