[code][code][code]Ok I created a database called Weblog and table called weblog in mySQL
such as:
[code]
CREATE TABLE weblog (
entrydate TIMESTAMP PRIMARY KEY,
entrytitle VARCHAR(100),
entrytext TEXT);
then I created a php file called addentry.php the form where people can filled and hit submit to send it to the database
[/code]
<HTML>
<HEAD>
<TITLE>Add a Weblog Entry</TITLE>
</HEAD>
<BODY>
<H1>Add an Entry</H1>
<form method="POST" action="addentry.php">
<b>Title:</b><br>
<input type="text" name="entrytitle"><br>
<b>Weblog Entry:</b><br>
<textarea cols="60" rows="6" name="entrytext">
</textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
</BODY>
<?php
if ($HTTP_POST_VARS['submit']) {
mysql_connect("localhost","root","root");
mysql_select_db("weblog");
$entrytitle=$HTTP_POST_VARS['entrytitle'];
$entrytext=$HTTP_POST_VARS['entrytext'];
$query ="INSERT INTO weblog (entrytitle,entrytext)";
$query.=" VALUES ('$entrytitle','$entrytext')";
$result=mysql_query($query);
if ($result) echo "<b>Successfully Posted!</b>";
else echo "<b>ERROR: unable to post.</b>";
}
?>
</HTML>
[/code]
then I create a weblog php files called weblog.php to show the result of when someone filled the form and click submit
[/code]
<html>
<head><title>Untitled</title></head>
<body>
<h1>Weblog Example</h1>
<dl>
<?php
mysql_connect("localhost","root","root");
mysql_select_db("weblog");
$query ="SELECT entrytitle, entrytext,";
$query.=" DATE_FORMAT(entrydate, '%M %d, %Y') AS date";
$query.=" FROM weblog ORDER BY entrydate DESC LIMIT 10";
$result=mysql_query($query);
while (list($entrytitle,$entrytext,$entrydate) =
mysql_fetch_row($result)) {
echo "<dt><b>$entrytitle ($entrydate)</b></dt>";
echo "<dd>$entrytext</dd>";
}
?>
</dl>
</body>
</html>
[/code]
The result didn't come out with what I am expecting, the result are Weblog Example and doesn't show any input.
Could someone take a look and let me know what is wrong, thanks.