对于大多数人来说,这可能是一个愚蠢的问题,但是当你需要使用ssh(安全shell)访问远程服务器时,我很难理解。使用MySQL数据库,您需要默认打开端口3306或更改MySQL中的任何设置,以便您通过网页将数据发送到数据库。提出这个问题的原因是我正在开发一个带有星级评分系统的网页,我遇到了一个问题,当你点击一个星星来评价一个项目,评级没有存储在数据库中。如果我手动将评级用于使用phpmyadmin,那么这些评级的结果会显示在页面上,但是当我点击星标来评价时,我仍然无法使用“INSERT INTO”将数据放入数据库。从阅读并在这里问另一个问题,这让我相信我需要设置'ssh'?访问我的测试服务器'打开端口3306',以便我可以从我的页面向我的数据库发送数据。这听起来对你们任何人都没问题吗?这是我从= http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html得到这个想法的链接之一。
如果没有,看起来我的代码有什么问题,使其无法处理代码端的问题吗?
<?php $ratingData = Rating::OutputRating('cams');
if (Error::HasErrors())
{
echo Error::ShowErrorMessages();
Error::ClearErrors();
}
else
{
echo $ratingData;
}
?>
以上是放置在我希望评级系统显示的页面中的代码。
class Rating
{
// Output the Rating information
// Returns a string of HTML
public static function OutputRating($varItem)
{
// Verify $varItem was provided
if ($varItem != null && strlen(trim($varItem)) != 0)
{
// Information for the Output
$averageStars = Rating::CalculateAverageRating($varItem);
// Check to see that the user has not already rated this item
if (Rating::CheckRatingsByIp($varItem) == 0)
{
$classes = "rating " . Rating::ShowStars($averageStars);
// Write Output HTML for the Rating Data
$output = "\r\n";
$output .= "<ul class=\"{$classes}\" id=\"{$varItem}\">\r\n";
$output .= " <li class=\"one\"><a href=\"javascript:RateItem('{$varItem}', 1);\" title=\"1 Star\">1</a></li>\r\n";
$output .= " <li class=\"two\"><a href=\"javascript:RateItem('{$varItem}', 2);\" title=\"2 Stars\">2</a></li>\r\n";
$output .= " <li class=\"three\"><a href=\"javascript:RateItem('{$varItem}', 3);\" title=\"3 Stars\">3</a></li>\r\n";
$output .= " <li class=\"four\"><a href=\"javascript:RateItem('{$varItem}', 4);\" title=\"4 Stars\">4</a></li>\r\n";
$output .= " <li class=\"five\"><a href=\"javascript:RateItem('{$varItem}', 5);\" title=\"5 Stars\">5</a></li>\r\n";
$output .= "</ul>\r\n";
}
else
{
$classes = "rated " . Rating::ShowStars($averageStars);
// Write Output HTML for the Rating Data
$output = "\r\n";
$output .= "<ul class=\"{$classes}\" id=\"{$varItem}\">\r\n";
$output .= " <li class=\"one\">1</li>\r\n";
$output .= " <li class=\"two\">2</li>\r\n";
$output .= " <li class=\"three\">3</li>\r\n";
$output .= " <li class=\"four\">4</li>\r\n";
$output .= " <li class=\"five\">5</li>\r\n";
$output .= "</ul>\r\n";
}
在我看来,$ rating数据会显示上面的2个html表中的一个,如果用户尚未对该项进行评级,则会显示第一个表。
function RateItem(varItemId, varRating)
{
var varOrigClassName = document.getElementById(varItemId).className;
// Retrieve Ajax Feeds
new Ajax.Request('RatingSystem/ajax.rate.item.php',
{
method: 'post',
parameters: {item: varItemId, rating: varRating, classes: varOrigClassName},
onSuccess: ReloadRating,
onFailure: RatingError
}
);
}
然后它将调用上面的函数
// Check that the data was sent
if (sizeof($_POST) == 0
|| $_POST['item'] == null
|| strlen(trim($_POST['item'])) == 0
|| $_POST['rating'] == null
|| strlen(trim($_POST['rating'])) == 0
|| $_POST['classes'] == null
|| strlen(trim($_POST['classes'])) == 0)
{
die("You shouldn't be attempting to access this file in this manner.");
}
echo Rating::RateItem($_POST['item'], $_POST['rating'], $_POST['classes']);
?>
这导致上面这段代码
public static function RateItem($varItem, $varRating, $varClasses)
{
$newClassNames = $varClasses;
// Verify $varName was provided
if ($varItem != null && strlen(trim($varItem)) != 0
&& $varRating != null && strlen(trim($varRating)) != 0 && is_numeric($varRating)
&& $varClasses != null && strlen(trim($varClasses)) != 0)
{
// Check to see that the user has not already rated this item
if (Rating::CheckRatingsByIp($varItem) == 0)
{
$ipAddress = $_SERVER['REMOTE_ADDR'];
Database::ExecuteQuery("INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES ('{$varItem}', {$varRating}, '{$ipAddress}', NOW())", "InsertRating");
Database::FetchResults("InsertRating");
Database::FreeResults("InsertRating");
Database::RemoveSavedResults("InsertRating");
然后到这个函数,它将把数据插入到我的表中。我从这个来源= http://www.search-this.com/2007/06/04/css-the-star-matrix-pre-loaded-part-2/获得了这个星级评分系统的代码。