I'm learning slowly but I cannot see why this code does not insert into the database, The page loads fine no errors at all, should I be useing VALUES? but thats not what's in the Tutorial I'm useing
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?PHP
include 'config.php';
include 'opendb.php';
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<BR>
Type Your Joke Here:- <BR>
Joke:<INPUT NAME ="joketext" type = "text">
<BR>
<INPUT TYPE="SUBMIT" NAME="submitjoke" id="SUBMIT" VALUE="SUBMIT">
</FORM>
<?PHP
//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 Joke:". mysql_error() ."</P>");
}
}
echo("<p>Here are all the jokes in My Database:-</p>");
//request text from all 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><BR><BR><BR>");
}
include'close.php';
?>
</body>
</html>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?PHP
include 'config.php';
include 'opendb.php';
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<BR>
Type Your Joke Here:- <BR>
Joke:<INPUT NAME ="joketext" type = "text">
<BR>
<INPUT TYPE="SUBMIT" NAME="submitjoke" id="SUBMIT" VALUE="SUBMIT">
</FORM>
<?PHP
//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 Joke:". mysql_error() ."</P>");
}
}
echo("<p>Here are all the jokes in My Database:-</p>");
//request text from all 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><BR><BR><BR>");
}
include'close.php';
?>
</body>
</html>