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

  • Home
  • SEARCH
  • 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 8213309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:04:16+00:00 2026-06-07T11:04:16+00:00

I am trying to write a dynamic form using PHP. I’d like to have

  • 0

I am trying to write a dynamic form using PHP. I’d like to have a single webpage that contains two forms:

  1. The upper form allows to search for an element in the mysql database, e.g., for a name
  2. The lower form shows the data that is associated with this name in the database

If I press on the “Search” button of the upper form, then the the lower form is shown and the text fields are filled with data from the database that belong to this name. If I change the user name to some other value and press again “Search”, then the data that is associated with the new record is shown and so on.

The lower form also has a button “Update” which allows to transfer changes made to the text boxes (in the lower part) to the database.

Now, I have the following problem: In my script I set initially the value of name (from the upper form) to “”. When I then press the “Search” button, then the lower part of the form is shown and the corresponding data is shown in the lower part. When I then press the “Update” button, then the text field associated with name is set to the empty string. This is because in my script I set initially name to the “”. I’d like that in this case the data entered in the upper form is not changed, i.e., it stays the same.

I guess, I am missing something here. There is probably an easy solution for this and I am doing something fundamentally wrong. It’d be great if you could help me.

That’s what I tried… I deleted lots of details, but I guess that can give you an idea what I am trying to do. Notice that the whole code is in the file update.php.

<?php
function search_bus($mysql, $name)
{
 // do some stuff here...
}

function update_bus($mysql, $b_id)
{
    // do some stuff here...
}

// some global variables
$b_id = 0;
$username = ""; // username of business

// get b_id that corresponds to username
if (isset($_REQUEST['search']))
{
    $b_id =0; // business id
    if (isset($_POST['user']))
    {
        $username = $_POST['user'];
        $b_id = search_bus($mysql, $username);
    }
}
elseif(isset($_REQUEST['update']))
{
    update_bus($mysql, $b_id);
}


?>

<h2>Search:</h2> 
<form name="search_bus" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Username: <input type="text" name="user" value="<?= htmlentities($username) ?>"/>
<input type="submit" value="Suchen" name="search"/>
</form>

<?php 
if($b_id != 0) 
{
?>

<h2>Data:</h2> 
<form name="business_design" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<-- some form follows here -->

<?php 
}
?>
  • 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-07T11:04:18+00:00Added an answer on June 7, 2026 at 11:04 am

    I think what you’re missing is to create a HTML Hidden field to keep the value of Name variable.

    <input type="hidden" name="name" value="<?php print $nameVar ?>" />
    

    Add this input to both forms so you can keep the value no matter what button the user clicks.

    Hope this helps.

    Adding code to verify the

    <h2>Search:</h2>  
    <form name="search_bus" method="post" 
    action="<?php echo $_SERVER['PHP_SELF'];?>">
    Username: <input type="text" name="user" value="<?= htmlentities($username) ?>"/>
    <input type="hidden" name="b_id" value="<?php print $b_id?>" />
    <input type="submit" value="Suchen" name="search"/> 
    </form>  
    
    
    <?php  if($b_id != 0)  { ?>  
    <h2>Data:</h2>  
    <form name="business_design" method="post" action="<?php echo $_SERVER['PHP_SELF'];>">      
    <input type="hidden" name="b_id" value="<?php print $b_id?>" />
    <-- some form follows here -->  
    <?php  } ?> 
    
    Dont initialize $b_id if it already comes into the http request.
    if (!isset($_POST['b_id']))
    {
     $b_id = 0; 
    }          
    else
    {
     $b_id = $_POST['b_id'];
    }
    

    This way you can alway remember the last selected value of b_id.
    Hope this can help you.

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

Sidebar

Related Questions

I'm trying to write dynamic method that calls Parallel.ForEach. I have checked a IL
I'm trying to write a dynamic form for models that allow users with different
Trying to write a chat, like on facebook, I wondered if two clients can
I am trying to learn how to write more dynamic web sites that use
Im trying to write a function that creates set of dynamic sublists each containing
I'm trying to write a dynamic control in Microsoft MVC that lets me edit
I'm trying to write a custom filter for Dynamic data that will allow me
I'm trying to write a fairly complex dynamic web page, using JQuery AJAX, and
I'm trying to write a dynamic Linq 2 Sql query using Expressions trees but
I'm trying to write a function in PL/PgSQL that have to work with a

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.