我想根据为每个月发布的文本创建的变量表来访问我的数据库中的文本。这是我的代码:
mybq_post_txt_act.php(相关部分) -
$month=date('m');
$host="localhost"; // Host name
$username="user"; // Mysql username
$password="pass"; // Mysql password
$db_name="db"; // Database name
$tbl_name_m="mybq_post_txt_main"; // Table name (main)
$tbl_name_p="mybq_post_txt_"."$month"; // table name (pool)
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
//create variable table
$sql_c =
"CREATE TABLE IF NOT EXISTS `mybq_post_txt`.`$month` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`username` varchar(20) NOT NULL,
`password` varchar(20) NOT NULL,
`message` varchar(160) NOT NULL,
`tag` varchar(60) NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`date` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=229";
mysql_query($sql_c);
// Get values from form
$user=mysql_real_escape_string($_SESSION['myusername']);
$myusername=mysql_real_escape_string($_POST['myusername']);
$mypassword=mysql_real_escape_string($_POST['mypassword']);
$mymessage=mysql_real_escape_string($_POST['mymessage']);
$mytag=mysql_real_escape_string($_POST['mytag']);
if ((!empty($mymessage)) && (!empty($mytag)))
{
// Insert data into mysql
$sql="INSERT INTO $tbl_name_m (username, message, tag, date)VALUES('$user', '$mymessage', '$mytag', CURDATE())";
$result=mysql_query($sql);
$sql="INSERT INTO $tbl_name_p (username, message, tag, date)VALUES('$user', '$mymessage', '$mytag', CURDATE())";
$result=mysql_query($sql);
}
// if successfully insert data into database, displays message "Successful".
if($result){
echo "<div class='center2'><font color='green'>Congratulations! Your post was Successful!</div>";
echo "<BR>";
}
else {
echo "<div class='center2'><font color='red'>You have one or more Invalid Entries. Your Post was not successful.</div>";
echo "<br>";
echo "<div class='center2'><font color='red'>Please go <a href='mybq-post-txt.php'>back</a> and try again.</div>";
echo "<br>";
}
}
else {
echo "<div class='center2'><font color='red'>Wrong Captcha. Your Post was not successful.</div>";
echo "<br>";
echo "<div class='center2'><font color='red'>Please go <a href='mybq-post-txt.php'>back</a> and try again.</div>";
echo "<br>";
}
?>
</div></td></tr>
<?php echo "<tr><td><div class='center2'><a href='mybq-index.php'>MyBQuotes main</a></div></td> <td><a href='mybq-post-txt.php'>Post Another</a></div></td></tr>"; ?>
</table>
</body> </html>
<? ob_flush();//Flush buffer output ?>
我一直收到自定义错误:“您有一个或多个无效条目。您的帖子不成功。”
你能帮忙吗?