<table cellspacing='0' cellpadding='0' border='0' background='none' style='font-family:arial;font-size:10pt;color:rgb(51, 51, 51);background-color:rgb(255, 255, 255);width:100%;'><tr><td valign='top' style='font: inherit;'>Greetings,<br><br><br>I'm learning PHP from a tutorial, and I'm unable to get the<br>following code to work (The code inserts a record into a MySQL database of jokes.):<br><br><br>-------------------------------------------------<br><br>// If a joke has been submitted,<br> // add it to the database.<br> if ("SUBMIT" == $submitjoke) {<br> $sql = "INSERT INTO Jokes SET " .<br> "JokeText='$joketext', " .<br> "JokeDate=CURDATE()";<br> if (mysql_query($sql)) {<br>
echo("<P>Your joke has been added.</P>");<br> } else {<br> echo("<P>Error adding submitted joke: " .<br> mysql_error() . "</P>");<br><br>-----------------------------------------------------<br><br><br>I'm using mysql-server-5.0, php5-mysql, and Dapper Drake Ubuntu 6.06. <br>I've given my mysql database files complete permissions, and checked the php <br>and mysql config files. I've also granted all privileges for the<br>database on root@localhost. Nonetheless, the code listed above doesn't<br>work, and I don't get any echoed confirmations or errors. Any advice<br>would be much appreciated. Here is the complete code for the PHP script:<br><br><br>----------- Complete PHP script -------------------<br><br><HTML><br>...<br><BODY><br><?php<br> // If the user wants
to add a joke<br> if (<span>isset</span>($addjoke)):<br>?><br><br><FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST><br><P>Type your joke here:<BR><br><TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP><br></TEXTAREA><BR><br><INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT"><br></FORM><br><br><?php<br> else:<br><br> // Connect to the database server<br> $dbcnx = @mysql_connect("localhost",<br> "root", "mypasswd");<br> if (!$dbcnx) {<br> echo( "<P>Unable to connect to the " .<br> "database server at this time.</P>" );<br> exit();<br> }<br><br> // Select the jokes
database<br> if (! @mysql_select_db("jokes") ) {<br> echo( "<P>Unable to locate the joke " .<br> "database at this time.</P>" );<br> exit();<br> }<br><br> // If a joke has been submitted,<br> // add it to the database.<br> if ("SUBMIT" == $submitjoke) {<br> $sql = "INSERT INTO Jokes SET " .<br> "JokeText='$joketext', " .<br> "JokeDate=CURDATE()";<br> if (mysql_query($sql)) {<br> echo("<P>Your joke has been added.</P>");<br> } else
{<br> echo("<P>Error adding submitted joke: " .<br> mysql_error() . "</P>");<br> }<br> }<br> <br> echo("<P> Here are all the jokes " .<br> "in our database: </P>");<br> <br> // Request the text of all the jokes<br> $result = mysql_query(<br> "SELECT JokeText FROM Jokes");<br> if (!$result) {<br> echo("<P>Error performing query: " .<br> mysql_error() . "</P>");<br> exit();<br> }<br> <br> //
Display the text of each joke in a paragraph<br> while ( $row = mysql_fetch_array($result) ) {<br> echo("<P>" . $row["JokeText"] . "</P>");<br> }<br> <br> // When clicked, this link will load this page<br> // with the joke submission form displayed.<br> echo("<P><A HREF='$PHP_SELF?addjoke=1'>" .<br> "Add a Joke!</A></P>");<br> <br> endif;<br> <br>?><br></BODY><br></HTML><br><br>---------------------------------------------------<br><br><br><br>Owen Pietrokowsky<br>opietro@yahoo.com<br></td></tr></table><br>