[CODE]
<HTML>
<BODY>
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Type your joke here:</P></BR>
<TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP></TEXTAREA></BR>
<INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT">
</FORM>
<?php
// Connect to the database server
{
$dbcnx = @mysql_connect("localhost", "root", "123456");
}
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 locate the joke database at this time.</P>" );
exit();
} // 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 submitted joke: " .
mysql_error() . "</P>");
}
}
// echo("<P> Here are all the jokes " . "in our database: </P>"); // Request the text of all the 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>");
}
// When clicked, this link will load this page
// with the joke submission form displayed.
?>
</BODY>
</HTML>
[/CODE]
其中[CODE]
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 submitted joke: " .
mysql_error() . "</P>");
}
}
[/CODE]
不会显示任何东西。
数据库jokes的表Jokes是这么建立的:
$sql = "CREATE TABLE Jokes ( " .
"ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, " .
"JokeText TEXT, " .
"JokeDate DATE NOT NULL " .
")";
<HTML>
<BODY>
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Type your joke here:</P></BR>
<TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP></TEXTAREA></BR>
<INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT">
</FORM>
<?php
// Connect to the database server
{
$dbcnx = @mysql_connect("localhost", "root", "123456");
}
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 locate the joke database at this time.</P>" );
exit();
} // 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 submitted joke: " .
mysql_error() . "</P>");
}
}
// echo("<P> Here are all the jokes " . "in our database: </P>"); // Request the text of all the 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>");
}
// When clicked, this link will load this page
// with the joke submission form displayed.
?>
</BODY>
</HTML>
[/CODE]
其中[CODE]
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 submitted joke: " .
mysql_error() . "</P>");
}
}
[/CODE]
不会显示任何东西。
数据库jokes的表Jokes是这么建立的:
$sql = "CREATE TABLE Jokes ( " .
"ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, " .
"JokeText TEXT, " .
"JokeDate DATE NOT NULL " .
")";
<HTML>
<BODY>
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Type your joke here:</P></BR>
<TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP></TEXTAREA></BR>
<INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT">
</FORM>
<?php
// Connect to the database server
{
$dbcnx = @mysql_connect("localhost", "root", "123456");
}
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 locate the joke database at this time.</P>" );
exit();
} // 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 submitted joke: " .
mysql_error() . "</P>");
}
}
// echo("<P> Here are all the jokes " . "in our database: </P>"); // Request the text of all the 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>");
}
// When clicked, this link will load this page
// with the joke submission form displayed.
?>
</BODY>
</HTML>
mysql_query($sql);
我觉得无论成功不成功都应该给出Your joke has been added.或者Error adding submitted joke: " . mysql_error()但是什么也没有啊。
{
echo 1;
$sql = "INSERT INTO Jokes SET " . "JokeText='$joketext', " . "JokeDate=CURDATE()"; //为什么执行到这一行就停止了?
echo 2;
if (mysql_query($sql))
{
echo("<P>Your joke has been added.</P>");
}
else
{
echo("<P>Error adding submitted joke: " .
mysql_error() . "</P>");
}
} 看看有没有1输出,提交没有如果有1再看看有没有2
+----+----------+------------+
| ID | JokeText | JokeDate |
+----+----------+------------+
| 1 | | 2011-09-14 |
| 2 | | 2011-09-14 |
| 3 | | 2011-09-14 |
| 4 | | 2011-09-14 |
+----+----------+------------+为什么文本没有插进去?
1.为了保险起见,变量使用前先赋值或初始化,你的$joketext没有赋值吧?2.调试数据库操作相关时,最好把操作的sql语句打印出来,便于查找错误而不至于很盲目。3.数据库插入为空,多半是变量没有取到值,你可以先$joketext=$_POST['joketext'];然后echo $joketext;看是否取到值了。
希望对lz有帮助。
哪有你那样写的。。我还以为你定义了$joketext变量。你不能直接$joketext而不定义。