Okay, I've installed Apache, PHP and mySQL on Win98. Great. I'm working through a tutorial on www.webmasterbase.com on mySQL and PHP. It's good. Here's my problem. The following code doesn't insert a record! Strangely, I've installed phpMyAdmin (just for the heck of it) and it will do an INSERT. I've tried some other table functions from the PHP manual and they work ...
I really dont want to resort to using phpMyAdmin cuz that defeats the purpose of learning mySQL and PHP I think! So can someone help explain what's going on here? Again, the phpAdmin version works... this one doesn't... HELP!
Thansk in advance
<HEAD>
<TITLE>Joke Submission Page</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<BODY bgcolor="#FFFFFF">
<?php // if user wants to add joke
if (isset($addjoke)): ?>
<TABLE WIDTH="500" border="0" cellspacing="2" cellpadding="2">
<tr><td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1"><b>Please add to the Database:</b></font></td></tr>
<tr><td><font face="Verdana, Arial, Helvetica, sans-serif" size="-1"><b>Your joke:</b></font></td></tr>
<tr><td><FORM ACTION="<?php echo ($PHP_SELF); ?>" METHOD="POST" >
<TEXTAREA NAME="joketext" COLS="75" WRAP="VIRTUAL"></TEXTAREA>
<INPUT TYPE="SUBMIT" NAME="submitjoke" VALUE="submitjoke"></FORM></td></tr>
<tr></TABLE>
<?php else:
// connect to the database server
$dbcnx=@mysql_connect ("localhost","mylog","mypass");
if (!$dbcnx) {
echo ("<P>Unable to connect to database at this time.</P>");
exit();
}
// get the Jokes database
if (! @mysql_select_db("Jokes")) {
echo ("<P> Unable to locate the Joke database at this time</P>");
exit();
}
// if joke has been submitted add to 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 ("Error adding Joke to Database: ".mysql_error()."</P>");
}
}
//<P> Here's all them Jokes you asked for:</P>
// Request the text of all the Jokes
$result=mysql_query(
"SELECT JokeText FROM Jokes");
if (!$result) {
echo ("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 the page
// with the joke submission form displayed
echo ("<P> <A HREF='$PHP_SELF?addjoke=1'>". "Add a joke!</A></P>");
endif;
?>
</BODY>