Build a database-driven website with PHP and MySQL (7)
Source: Internet
Author: User
Now we have a program code that allows users to input a joke and add it to our database. The rest is to add it to the joke display page we have prepared. Because the vast majority of users only want to watch jokes, we do not want to make major changes to our pages unless the user says they want to add a new joke. For this reason, our application should be a multi-functional page. The following is the code of the program:
<HTML>
...
<BODY>
<? Php
// If the user wants to add a joke
If (isset ($ addjoke )):
?>
<Form action = "<? Php echo ($ PHP_SELF);?> "METHOD = POST>
<P> Type your joke here: <BR>
<Textarea name = "joketext" ROWS = 10 COLS = 40 WRAP> </TEXTAREA> <BR>
<Input type = submit name = "submitjoke" VALUE = "SUBMIT">
</FORM>
<? Php
Else:
// Connect to the database server
$ Dbcnx = @ mysql_connect ("localhost ",
"Root", "mypasswd ");
If (! $ Dbcnx ){
Echo ("<P> Unable to connect to ".
"Database server at this time. </P> ");
Exit ();
}
// Select the jokes database
If (! @ Mysql_select_db ("jokes ")){
Echo ("<P> Unable to locate the joke ".
"Database at this time. </P> ");
Exit ();
}
// If a joke has been submitted,
// Add it to the database.
If ("SUBMIT" = $ submitjoke ){
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service