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;
|