php和MySQL中简单的喜欢/不喜欢评级系统 [英] Simple like/dislike rating system in php and MySQL

查看:93
本文介绍了php和MySQL中简单的喜欢/不喜欢评级系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的随机视频网站(id = youtube id)添加一个简单的评分系统
我在php和MySQL方面没有太多经验,并且不确定如何使用提交按钮以这种方式更新字段:

I want to add a simple rating system to my random video site (id = youtube id)
I don't have much experience with php and MySQL and I'm not sure how to update a field using submit buttons in this way:

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" name"rateform">
  <input name="rateup" type="image" src="up.png" id="rateup" value="rateup" />
  <input name="ratedown" type="image" src="down.png" id="ratedown" 
   value="ratedown" />
</form>
<?PHP
mysql_connect(",",",",",")or die(mysql_error());
mysql_select_db(",")or die(mysql_error());
if ($_POST['rateup'])
{
    mysql_query("UPDATE utube SET rating = rating + 1 
                WHERE (id = $pageid)");} else if ($_POST['ratedown']) {
    mysql_query("UPDATE utube SET rating = rating - 1 
                WHERE (id = $pageid)");}

?>

是否需要做一些将html和php链接在一起的事情?
所有的语句本身都会返回正确的值(即$ pageid)
但是当我按下按钮时,任何字段都没有任何反应.

Is there something I have to do to link the html and php together?
All of the statements return the correct values by themselves (i.e $pageid)
but when I press the buttons there is nothing happening to any fields.

当我将mysql查询直接放入phpmyadmin时,它也有效,
我只是不确定html如何与php通信?
如果有人告诉我这是如何工作的,我将不胜感激,这样我就可以使我的脚本正常工作.

When I put the mysql query directly into phpmyadmin it also works,
I'm just not sure about how the html communicates with the php?
I'd appreciate if someone were to inform me of how this works so I can get my script to work.

推荐答案

让我们开始发现问题:我只能想象两个原因:

Let's start finding the problem: I can only imagine two reasons for this:

  • PHP未连接到数据库.尝试直接从脚本执行查询(将其从if语句中删除.
  • 由于某些原因,if语句是错误的:尝试将mysql_query替换为print('up');print('down');
  • PHP is not connecting to the DB. Try executing the query directly from your script (taking it out of the if statement.
  • The if statement is wrong for some reason: Try replacing the mysql_query with print('up'); and print('down');

顺便说一句,else if是一个单字语句.您可以将其替换为elseif.

By the way, else if is a one-word-statement. You can replace it with elseif.

这篇关于php和MySQL中简单的喜欢/不喜欢评级系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆