Hi, I'm working locally so I guess I'll have to post my code here, sorry.
My problem is that I keep getting a warning saying that a variable that I'm using isn't being defined. And I see what it means: the variable is only being defined when the form has NOT been submitted (when it IS submitted I do not get the warning). But...I don't want the warning to show up, you know?
Btw today is my very first day of messing with php and mysql so please be kind : )
Here's the code:
/////////////////////////////////////////
<?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:
//FUCKING DEFINING THE FUCKING VARIABLE, @!#$
//Connect to database server
$dbcnx = @mysql_connect("rwoolford-srv", "root", "");
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 connect to the " .
"database server at this time.</p>"
.
mysql_error()
);
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 joke: "
.
mysql_error() . "</p>");
}
}
// If a joke has been deleted, remove it from the database
if (isset($deletejoke)) {
$sql = "DELETE FROM Jokes
WHERE ID=$deletejoke";
if (@mysql_query($sql)) {
echo("<p>The joke has been deleted.</p>");
} else {
echo ("<p>Error deleting joke: " .
mysql_error() . "</p>");
}
}
echo("<p> Here are the jokes in our database: </p>");
// Request the ID and text of all the jokes
$result = @mysql_query("SELECT ID, JokeText FROM Jokes");
if (!$result) {
echo ("<p>Error performing querey: " . mysql_error()
. "</p>");
exit();
}
// Display the text of each joke in a paragraph with delete joke link next to it
while ( $row = mysql_fetch_array ($result) ) {
$jokeid = $row["ID"];
$joketext = $row["JokeText"];
$submitjoke = "poop";
echo ("<p>$joketext " .
"<a href='$PHP_SELF?deletejoke=$jokeid&?addjoke=1'>"
.
"Delete Joke</a></p>");
}
// Displays the Add a Joke form
echo ("<p><a href='$PHP_SELF?addjoke=1'> Add a Joke</a></p>");
endif;
?>