Jump to content

last step, updating data in table...passing data


crmamx

Recommended Posts

I can add and delete data from my table. Now I need to be able to change one or more fields in an entry. So I want to retrieve a row from the db, display that data on a form where the user can change any field and then pass the changed data to an update.php program.

 

I know how to go from form to php. But how do I pass the data from retrieve.php to a form so it will display? Do I use a URL and Get? Can I put the retrieve and form in the same program?

 

 

Link to comment
Share on other sites

Thanks Denno, but I guess my request was not clear.

 

retrieve.php will get the data from the db.

form1.html will display the retrieved data.

update.php will update the db.

 

How do I get the retrieved variables from retrieve.php to form1.html?

Link to comment
Share on other sites

Oh I see..

 

Well you can't have form1.html as a HTML file, it will need to be php. You then include retreive.php.

 

If your form code, you will add the value="" property to each form field, and then inside the doube quotes for each value, you will echo the php variable that holds the correct text for that field.

 

Example: You pull a name from the database and display it in the form

//connect to mysql

//run query to grab the information from the database
//loop through the query result set, putting each column into it's own variable
//you should have a variable $name = $row["name"];

//start printing all of your form code
//the HTML/PHP code for the name text field will be
<input type="text" name="name" value="<?php echo $name; ?>"/>
//end your form printing.

 

So you can see I've got lots of pseudo code above, but that's because I'm assuming you already know how to complete those parts.

 

Hope that helps

 

Denno

Link to comment
Share on other sites

Well you can't have form1.html as a HTML file, it will need to be php. You then include retreive.php.

If that is the case, why do I need an include?

 

Example: You pull a name from the database and display it in the form

//connect to mysql
//run query to grab the information from the database
//loop through the query result set, putting each column into it's own variable
//you should have a variable $name = $row["name"];
//start printing all of your form code
//the HTML/PHP code for the name text field will be<input type="text" name="name" value="<?php echo $name; ?>"/>
//end your form printing.

Can I do it like this?

 

retrieve_data.php

// php retrieve data
// html create form and echo data into form, action=update.php method=post

update.php

//grab variables using $_POST['var_name'];
//Update db

 

 

Link to comment
Share on other sites

lol. You can. I was going to suggest that, but then I figured you might like to keep it separate so that it was easy to understand. As retrieve.php doesn't really hint at their being a form inside it.

 

But yes, you can echo the form out in retrieve.php most definitely.

 

Denno

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.