Although you don't show it in your snippet of code, the script in question
starts with:

if (isset($addjoke)): // If the user wants to add a joke

So all he's doing is setting the variable $addjoke. It could have been set
to 2 or something else, although 1 kind of makes more sense because it's
associated with "true" (as 0 is associated with "false").

--
Lowell Allen

> From: "Anthony Ritter" <[EMAIL PROTECTED]>
> Date: Thu, 30 Jan 2003 18:30:28 -0500
> To: [EMAIL PROTECTED]
> Subject: [PHP] php question - query string
> 
> The following script is from Kevin Yank's book on page 59-60.  (Sitepoint)
> 
> I'd like to get some clarification about the line: (almost next to last line
> in the script)
> 
> ....................
> echo("<p><a href='$PHP_SELF?addjoke=1'>Add a Joke!</a></p>");
> .................
> 
> 
> He has a link called "Add a Joke!".
> 
> When the user clicks on the link, the same page loads - with the form this
> time - and the query string passes the value -1 - to the variable $addjoke.
> 
> Am I on the right track?
> 
> If so, why does 1 - as opposed to 2 or something else - have to be the
> name/value pair if the user is adding another joke?
> 
> Thank you.
> TR
> .......................................
> 
> <html>
> <head>
> <title> The Internet Joke Database </title>
> </head>
> <body>
> <?php
> if (isset($addjoke)): // If the user wants to add a joke
> ?>
> 
> <form action="<?=$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" /></p>
> </form>
> 
> <?php
> else: // Default page display
> 
> // Connect to the database server
> $dbcnx = @mysql_connect("localhost", "root", "mypasswd");
> if (!$dbcnx) {
> echo( "<p>Unable to connect to the " .
> "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 ($submitjoke == "SUBMIT") {
> $sql = "INSERT INTO Jokes SET
> JokeText='$joketext',
> JokeDate=CURDATE()";
> if (@mysql_query($sql)) {
> echo("<p>Your joke has been added.</p>");
> } else {
> echo("<p>Error adding submitted joke: " .
> mysql_error() . "</p>");
> }
> }
> 
> echo("<p> Here are all the jokes in our database: </p>");
> 
> // Request the text of all the jokes
> $result = @mysql_query("SELECT JokeText FROM Jokes");
> if (!$result) {
> echo("<p>Error performing query: " . mysql_error() . "</p>");
> exit();
> }
> 
> // Display the text of each joke in a paragraph
> while ( $row = mysql_fetch_array($result) ) {
> echo("<p>" . $row["JokeText"] . "</p>");
> }
> 
> // When clicked, this link will load this page
> // with the joke submission form displayed.
> echo("<p><a href='$PHP_SELF?addjoke=1'>Add a Joke!</a></p>");
> 
> endif;
> 
> ?>
> </body>
> </html>
> 
> --
> 
> 
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to