Download Document 7760007

yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts

Object-relational impedance mismatch wikipedia, lookup

Microsoft SQL Server wikipedia, lookup

Clusterpoint wikipedia, lookup

Open Database Connectivity wikipedia, lookup

Relational model wikipedia, lookup

Database model wikipedia, lookup

Inserting Data into the Database
Inserting Data into the Database
In this section, we'll see how we can use all the tools at our disposal to allow visitors to our site to add their own jokes to the database. If you enjoy a challenge,
you might want to try to figure this out on your own before you read any further.
There is little new material in this section. It's mostly just a sample application
of everything we've learned so far.
If you want to let visitors to your site type in new jokes, you'll obviously need a
form. Here's the code for a form that will fit the bill:
<form action="<?=$_SERVER['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" />
As we've seen before, this form, when submitted, will load the very same page
(because we used the $_SERVER['PHP_SELF'] variable for the form's action attribute), but with two variables attached to the request. The first, joketext, will
contain the text of the joke as typed into the text area. The second, submitjoke,
will always contain the value "SUBMIT"; the presence of this variable is a signal
that a joke has been submitted. Both of these variables will appear in the $_POST
and $_REQUEST arrays created by PHP.
To insert the submitted joke into the database, we just use mysql_query to run
an INSERT query, using the $joketext variable for the value to be submitted:
if (isset($_POST['submitjoke'])) {
$joketext = $_POST['joketext'];
$sql = "INSERT INTO Jokes SET
if (@mysql_query($sql)) {
echo('<p>Your joke has been added.</p>');
} else {
echo('<p>Error adding submitted joke: ' .