Re: editing a mysql record using php and website ?
- From: Scott Johnson <futureshock@xxxxxxx>
- Date: Mon, 09 Nov 2009 11:26:48 -0800
PAkerly wrote:
Hello,
I have a page that asks a user to enter a record ID number. When they
hit submit I want another page to come up that will call code like
this:
sql = "SELECT id, cause, vendor, date
FROM mydb
WHERE ID = '$_POST[txtrecordid]'"
^^is the above right?
and then I have txt boxes on the page that I want to fill in based on
the record id.
ie. txtvendor, txtdate, txtcause
how do I fill these in with the data?
And then when I hit submit I want to insert the new data into the
DB...not as a new record but just changing the record....so if
txtcause says B-Failure and I change it to A-Failed I cant it to
change....so I want the recordID to stay the same...How would I do
this?
If you KNOW its a single record, load the data into an array and then index the array into the text fields.
// pull results
$result = mysql_query($sql)
//load data into the array
// this will load the single record into the array and be indexed on // // either 0 base or assoc by column name
$data_array = mysql_fetch_assoc($result)
// load the data into the text field
echo "<input type='text' name='txtvendor' value='".$data_array['txtvendor']."' />"
echo "<input type='text' name='txtcause' value='".$data_array['txtcause']."' />"
.......
If you have several records then you will need to step through the results.
This will load one record at a time from the results
while($data_array = mysql_fetch_assoc($result)) {
//insert your html input fields here
}
This is a VERY simplified example, you will still need error checking a protection from a host of other issues, but this is a basic frame work the works.
Good luck
Scotty
.
- References:
- editing a mysql record using php and website ?
- From: PAkerly
- editing a mysql record using php and website ?
- Prev by Date: Re: reflection in init() functions
- Next by Date: Re: reflection in init() functions
- Previous by thread: Re: editing a mysql record using php and website ?
- Next by thread: Re: editing a mysql record using php and website ?
- Index(es):
Relevant Pages
|