我一直试图让这个系统工作几个小时,但仍然无法让它工作。这是教程的直接复制/粘贴,显然它适用于许多其他人,所以我不明白为什么它对我不起作用!该表已创建,因此根本不是问题......系统不会向mysql数据库输入任何内容,我也没有收到任何错误!!!!
该教程可以在这里找到:http: //www.codingforums.com/archive/index.php/t-46916.html
我知道这不是一个安全的系统,但只要我能让它工作,我就会解决它!
这是代码:
配置文件
<?php
$dbhost="localhost";
$dbusername="myusernam";
$dbpassword="mypass";
$dbname="dataname";
$connect = mysql_connect($dbhost, $dbusername, $dbpassword);
mysql_select_db($dbname,$connect) or die ("Could not select database");
?>
add_news.php
<?php
include("config.php");
if($submit)
{//begin of if($submit).
// Set global variables to easier names
$title = $_POST['title'];
$text1 = $_POST['text1'];
$text2 = $_POST['text2'];
//check if (title) field is empty then print error message.
if(!$title){ //this means If the title is really empty.
echo "Error: News title is a required field. Please fill it.";
exit(); //exit the script and don't do anything else.
}// end of if
//run the query which adds the data gathered from the form into the database
$result = mysql_query("INSERT INTO news (title, dtime, text1, text2)
VALUES ('$title',NOW(),'$text1','$text2')",$connect);
//print success message.
echo "<b>Thank you! News added Successfully!<br>You'll be redirected to Home Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=index.php>";
}//end of if($submit).
// If the form has not been submitted, display it!
else
{//begin of else
?>
<br>
<h3>::Add News</h3>
<form method="post" action="<?php echo $PHP_SELF ?>">
Title: <input name="title" size="40" maxlength="255">
<br>
Text1: <textarea name="text1" rows="7" cols="30"></textarea>
<br>
Text2: <textarea name="text2" rows="7" cols="30"></textarea>
<br>
<input type="submit" name="submit" value="Add News">
</form>
<?
}//end of else
?>
news_view.php
<?php
// load the configuration file.
include("config.php");
//load all news from the database and then OREDER them by newsid
//you will notice that newlly added news will appeare first.
//also you can OREDER by (dtime) instaed of (news id)
$result = mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect);
//lets make a loop and get all news from the database
while($myrow = mysql_fetch_assoc($result))
{//begin of loop
//now print the results:
echo "<b>Title: ";
echo $myrow['title'];
echo "</b><br>On: <i>";
echo $myrow['dtime'];
echo "</i><hr align=left width=160>";
echo $myrow['text1'];
// Now print the options to (Read,Edit & Delete the news)
echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">Read More...</a>
|| <a href=\"edit_news.php?newsid=$myrow[newsid]\">Edit</a>
|| <a href=\"delete_news.php?newsid=$myrow[newsid]\">Delete</a><br><hr>";
}//end of loop
?>