Simple like/dislike rating system in php and MySQL

折月煮酒 提交于 2019-12-03 16:23:09

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

  • 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');

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

arch

Image buttons post clicked coordinate value except form name. inputname_x & inputname_y

if ($_POST['rateup_x'])
{
    mysql_query("UPDATE utube SET rating = rating + 1 
      WHERE (id = $pageid)");} else if ($_POST['ratedown_x']) {
    mysql_query("UPDATE utube SET rating = rating - 1 
      WHERE (id = $pageid)");}
<?PHP
mysql_connect("hostname","username","password")or die(mysql_error());
mysql_select_db("dbname")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)");}

?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!