cheap nfl jerseys china cheap nfl jerseys free shipping wholesale nfl jerseys china wholesale jerseys from china cheap nfl jerseys free shipping cheap nfl jerseys for sale cheap jerseys free shipping wholesale nfl jerseys from china cheap nfl jerseys sale cheap nike nfl jerseys china wholesale jerseys free shipping cheap nfl jerseys wholesale wholesale nfl jerseys online cheap nfl jerseys wholesale china jerseys wholesale cheap coach handbags outlet authentic designer handbags cheap coach handbags outlet cheap coach purses outlet discount coach bags coach bags sale coach purse outlet cheap real coach purses coach handbags sale online coach purse outlet michael kors outlet online store cheap michael kors bags cheap michael kors purse michael kors factory outlet online cheap michael kors handbags cheap michael kors purses michael kors bags outlet online cheap michael kors purse michael kors handbags discount
MySQL & PHP

Insert, Update and Delete


Now that you know how to get the data out of the database, it also helps to know how to stuff it back in again. Most of the users you're writing these database applications for don't know how to write SQL inserts on their own, and/or you don't want to give them full access to your database.

The easiest way around these problems is to create an HTML form which asks them nicely for the information you want. When the form is submitted, a PHP script will read the information and stuff the results into the database. When PHP is called as the action to a form, all of the form variables are created as PHP variables. i.e. If your HTML form says:

    <input type=text name=Name size=20>

Then the PHP script can reference the variable $Name.

    echo("The name you entered was: $Name\n");

Actually, all of these three database routines are SQL calls that don't return anything other than the number of affected rows. The Perl DBI interface lumps them all under the "do" directive. It would certainly be possible to do the same thing under PHP. I've chosen to break it out into three separate calls because having different routine names makes the code you write a bit easier to read. Self-documentation is all it is.

4.1 Insert

    $sql->Insert("insert into TEST values (0,'J.D.','18','23000')");
    $affected_rows = $sql->a_rows;
    

4.2 Update

    $sql->Update("update TEST set Name = 'Jane Doe' where ID = 6");
    $affected_rows = $sql->a_rows;
    

4.3 Delete

    $sql->Delete("delete from TEST where ID = 4");
    $affected_rows = $sql->a_rows;
    
Back Index Next Chapter

Vt. Web Wizard Home    |     Email Questions & Comments

© 1998 Vt. Web Wizard