Updating MySQL with PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
The page I want to update is similar to "http:www.hospiceslo.org/events.php"
(read only). On my update page I've got the same table as a FORM where the
client can make changes to the fields. The problem I'm having is updating
the MySQL data base with the content of the form. I have no clue and would
like to know where to start. Can I get some pointers to references or
examples, even suggestions, on how this can be successfully done?

Re: Updating MySQL with PHP

Ronald Schow wrote:
Quoted text here. Click to load it

Without checking what the user has sent

//assume you have already connected to the database
//if not see the online manual for mysql_connect()
$query("UPDATE tablename SET column1='',
column2='', column3='' WHERE

In your form you have a hidden field keycolumn which has the rows primary key
value and then you name the options that the user can update for column1,
column2, ...



Re: Updating MySQL with PHP

J.O. Aho wrote:

Quoted text here. Click to load it


$query = sprintf("UPDATE tablename"
                ." SET column2='%s', column3='%s'"
        ." WHERE column1='%s';"

Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 27 days, 11:55.]

                               PHP Linkifier

Re: Updating MySQL with PHP

Quoted text here. Click to load it

Be sure to clean your input before you put it into the database, that  
certainly could present a problem in the future if someone tries an  
Injection attack.  As for using the $_REQUEST array, try to use the more  
specific $_GET or $_POST arrays, as the ability to send data through two  
methods could cause problems if someone tries to maliciously insert data.


Site Timeline