Re: editing a mysql record using php and website ?



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
.



Relevant Pages

  • Re: Loading combos with static info
    ... I don't want to hit the database ... when forms load over and over again. ... Should I load the database info into an array once and ...
    (microsoft.public.vb.general.discussion)
  • Re: Loading combos with static info
    ... I don't want to hit the database ... when forms load over and over again. ... Should I load the database info into an array once and ...
    (microsoft.public.vb.general.discussion)
  • Why wont this form post session variables?
    ... and when I fill the form and hit the submit button, ... HTTP_SESSION_VARS array does not seem to take any of the values set out ... unset; ... echo 'Enter in a new episode in plot point form.'; ...
    (php.general)
  • Re: Is Way Search for Characters Separated by Unknown Number of Between Characters?
    ... character sequence in the 800 3 array. ... I got hit in second row, ... TAA TAC TAG TAT TAU ...
    (comp.lang.apl)
  • Re: fast stable sort
    ... For fastest load, at expense of slower sort, you ask the operating ... and you memory-map the file directly into that array. ... memory of your big array. ... possible to assure locality of reference and thus avoid thrashing ...
    (comp.programming)