Home  |  About  | Last |  Submit  |  Contact
AllQuests.com




Previous Question:  Calculateing value of web site  eCommerceNext Question:  Opinions on Merchant Accounts Express  eCommerce
Question PHP help ( SitePoint Forums Just Starting Your Design )
Updated: 2008-08-12 07:19:35 (2)
PHP help

I recently started learning PHP because I need to set up a news updater via forms for a client. Right now I'm having trouble with a piece of code I got from a tutorial. Would you please help me find the error? The code is:

<HTML>
<HEAD>
<TITLE> Our List of Jokes </TITLE>
<HEAD>
<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 hereBR>
<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", "password");
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 ("SUBMIT" == $submitjoke) {
$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("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>");
}

// Whe 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>

It returns this:

Warning: Undefined variable: submitjoke in c:\Inetpub\wwwroot/db2.php on line 38

Thanks in advance.

Answers: PHP help ( SitePoint Forums Just Starting Your Design )
PHP help

Change this
if ("SUBMIT" == $submitjoke) {

To This
if (isset($submitjoke)){

manipura

PHP help

Thanks a lot, friend. That solved the problem. See you around.

~"Le diable c'est porc."~
Hermes Pinz?n Galarza

Yonko

Previous Question:  Calculateing value of web site  SitePoint Forums  eCommerceNext Question:  Opinions on Merchant Accounts Express  SitePoint Forums  eCommerce

- Source: PHP help SitePoint Forums Just Starting Your Design
- Previous Question: Calculateing value of web site SitePoint Forums eCommerce
- Next Question: Opinions on Merchant Accounts Express SitePoint Forums eCommerce