Documente Academic
Documente Profesional
Documente Cultură
Send an email to the mailing iist using the Send Email form.
Download the code for the Send Email web page from the Head First l.abs web site m """d thit
at www. headf irstlabs . com/books/hfphp It’s in the chapter03 folder. Similar to the your email addrea
Add Email page you saw carlier. titis code consists of a vveh form in sendemail. w.ll need io be o"
html. a slyle sheet istyle . css). and a couple of images elvislogo. gif and blankf ace. •the ma<lir>5 Iist'«
jpg . order far you to
iretewe a message
Create a new tcxt file called sendemail .php, and enter all of the code on the faring
page. Upload all of these Oles to your web server and open the sendema il. html
page in a web browser. Enter an email message in the form, and rlick Submit.
www.it-ebooks.info
ourappneeds elere
functionality
Sowetiwes
people want
out
As with i.nv blossonting
new business, there are
bunips in the road. ll
seemssome Elvis lans
havejumped ship on the
King and want ofT
Elmer's mailing Iist.
Elmer wants to oblige.
but that means he needs
to remove the customers
from his database.
Dear Elmer.
I do not wisti to
roce'veany more
sales emailsf« WBv
Store. I'm still a fan
of Elvis but I can no
longer look the pari
Please take me off of
your Iist My email is
cbriggs@boards-r-
us.com.
Thanks.
An Ex-lmpersonator
Vours Truly,
Brian Powers Elmer’s not too haf?y dbout
bp@honey-doit.com losinj Customers, but he
wants to honor fhenr rejvesb
to be removed from his
mailing Iist-
h’s a laci of MySQL lifc sometitnes you need to remove data from your database. Elmer needs to expand bis
applieation to delete users from theemai 1 Iist lable.
Write down the new applieation componcnts you think Elmer is going to
need to implement the Remove Email fcatnre:
146 Chapter 3
www.it-ebooks.info
No, not at all. DELETE can be used to pinpoint a specific row or rows
for deietion.
To precisely target the row or rows you w ani lo delete with DELETE. you need to tark
on a WHERE clause. If yon recall from using it with the SELECT eommand. WHERE
allows you to isolate speeilic rows in a (|uery.
_ v^harpen your
DELETEpencil
r h WHERE
Suppose Elmer had 23 customers with a first name of Anne, 11 customers with a last
Y^Harpen your name of Parker, and one customer with the name Anne Parker. Write down how
pencil many rows of data are deleted by each of these gueries.
DELETE FROM email Iist WHERE first name = 'Anne' OR last name = 'Parker';
A WHERE
DELETE FROM email Iist WHERE last name = Parker; clause narrovs down a f|ueiy
WHERE
Suppose Elmer had 23 customers lo focus on speeilic rows
last ol
T' Te.tkwith a first name
<\uestior.l of Anne,
The last na»e 11
isucustomers
t with a
The name of a name of Parker, and one
Th.s pa*-t customer
of the WHER&
'' ---- withtlause
<\uoted, the
SOname Anne
no rows 3rtParker.
deletedWrite
- all down
— how
DELETE
'table FROM
tolwvinFROM
DELETE email
email Iist
@honey-doit.com'
many
Iist WHERE rows
last
first of
namedata==
name
performs are deleted
aParker;
'Anne';
'Anne'
test on
The by each
ORte*t
every tovaof
www.it-ebooks.info
last
row
value these
name
toues
«atth = be
«u»st <\uotedyou are here ► 11 147
gueries. dai
'Parker'; a.
Use WHERE to PEIETE specific data
I5y using n WHERE clause with the DELETE eommand, we target speeilic rows of data for
deietion, instead of emptying an entire table. The 'WHERE clause lets us l'ocus onjtlst the row we
w ant to remove. in this case one of FJmer’s customers who wants to he removed from the
mailing Iist.
The ... tual test witl.in a WHERE clause perlorms a comparison that is carried
out against every row in the table. In this examplc, the equ;il sign .=) lests
each value in the email coluinn lo see whieh rows are equal to "pr@honey-
doit.com". If the value in the email eoluntn of a row matehes. then that row
will be deleted.
Writo down why you think thi* intai 1 eoluntn is used in the WHERE
clause, as opposed to f irst_name or last_name:
148 Chapter 3
www.it-ebooks.info
www.it-ebooks.info
DRII /0 --------------------------------------
Try out the DELETE eommand on Elmer’s database.
Fire up a MVSQL tool and try a few DELETE commands to delete individual n.ws
uf data from the email Iist lable bascd on customers' email addresses. Just make
sure to include a VIHERE clause on each DELETE statement so that you don't
accidentally wipe out the wliole table)
That’s right. Deleting users by hand with individual queries is no way to manage a mailing Iist.
Since Elmer will inevilably lace users who want to be removed from his mailing Iist in the liiture. it makes a lot of sense (o
rlevelop a welj-based user interface for removing customers. An HTML web form and l’HI’ seript shotild do the trick, not to
mention a DELETE FROM query with a little help from a WHERE i lause...
150 Chapter 3