Jump to content

Populate Form Fields from database


bullbreed

Recommended Posts

Im trying to learn php my developing a CMS (I know, what a mad man I hear you say)  :P

 

I have a page where you can add the data for your webpage but now I want to edit the info.

So I created a page that calls all the pages up in to a table on x-screen with an edit link at the end.

 

I want to edit the Home page. Here is the table on screen;

 

Page Name-----------------Action

Home--------------------------Edit (Link)

About US-----------------------Edit (Link)

 

When you click on the Edit (Link) for the Home page you go to this Url - editpage.php?p=Home

I want the form fields on this page to be populated with the info from the database related to the Home page.

 

What value do I put in to the form fields to call the info related to the Url ?p=Home.

 

So lets say its the page name form field I want to edit. I want it to do something like

Echo the value from the page_name column in the database relative to the Home page in the URL.

 

I hope I make sense

 

Regards

Link to comment
https://forums.phpfreaks.com/topic/191051-populate-form-fields-from-database/
Share on other sites

You would first run a query for whatever you wanted to pull from the database and set it to a variable. Example:

$result = mysql_query("SELECT * FROM table WHERE pagename = 'home'");
	while ($row = mysql_fetch_array($result)) {
						$fieldyouwant=$row["fieldyouwant"];
}

 

Then to call it in your form you just echo it out.

<input type="text" value="<? echo $fieldyouwant; ?>" name="fieldname" />

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.