Seker Posted May 9, 2012 Posted May 9, 2012 (edited) Okay, been tinkering. The Invalid ID is gone, but now, it just says "You have rated up!" (No user id or name if I try that) and it doesn't update the ratings count. viewuser.php: Ratings: Up - <a href='ratings.php?plus_rate={$r['userid']}'>{$r['prate']}</a> Down - <a href='ratings.php?minus_rate={$r['userid']}'>{$r['mrate']}</a> ratings.php: <?php session_start(); require "global_func.php"; if ($_SESSION['loggedin'] == 0) { header("Location: login.php"); exit; } $userid = $_SESSION['userid']; require "header.php"; $h = new headers; $h->startheaders(); include "mysql.php"; global $c; $is = mysql_query( "SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid", $c) or die(mysql_error()); $ir = mysql_fetch_array($is); check_level(); $fm = money_formatter($ir['money']); $cm = money_formatter($ir['crystals'], ''); $lv = date('F j, Y, g:i a', $ir['laston']); $h->userdata($ir, $lv, $fm, $cm); $h->menuarea(); global $r,$ir,$c; $action = $_GET['action']; $opdata = $r['userid']; switch ($_GET['action']) { case 'plus_rate': do_plus_rating(); break; case 'minus_rate': do_minus_rating(); break; } if(!$action) { echo "Error - invalid action."; $h->endpage(); exit; } function do_plus_rating() { global $r,$ir,$c; if ($r['userid'] == $ir['userid']) { print "You cannot rate yourself!<br /> <a href='viewuser.php?u={$r['userid']}'>Back</a>"; } else { mysql_query("UPDATE users SET prate=prate+1 WHERE userid={$r['userid']}"); print "You have rated {$r['userid']} up!<br /> <a href='viewuser.php?u={$r['userid']}'>Back</a>"; } } function do_minus_rating() { global $r,$ir,$c; if ($r['userid'] == $ir['userid']) { print "You cannot rate yourself!<br /> <a href='viewuser.php?u={$r['userid']}'>Back</a>"; } else { mysql_query("UPDATE users SET mrate=mrate+1 WHERE userid={$r['userid']}"); print "You have rated {$r['userid']} down!<br /> <a href='viewuser.php?u={$r['userid']}'>Back</a>"; } } $h->endpage(); ?> Edited May 9, 2012 by Seker Quote
HauntedDawg Posted May 10, 2012 Posted May 10, 2012 Do you have prate and mrate in your DB? Run this query, ALTER TABLE `users` ADD `mrate` INT(5) UNSIGNED DEFAULT '0'; ALTER TABLE `users` ADD `prate` INT(5) UNSIGNED DEFAULT '0'; Then try, or post your error's Quote
Seker Posted May 10, 2012 Author Posted May 10, 2012 Do you have prate and mrate in your DB? Run this query, ALTER TABLE `users` ADD `mrate` INT(5) UNSIGNED DEFAULT '0'; ALTER TABLE `users` ADD `prate` INT(5) UNSIGNED DEFAULT '0'; Then try, or post your error's prate and mrate are both in the users table. Gives no errors. Just says: "You have rated up! Back" And it doesn't update the table, or the count on the viiewuser. Quote
HauntedDawg Posted May 10, 2012 Posted May 10, 2012 (edited) Old Code --too short Edited May 10, 2012 by HauntedDawg Quote
Seker Posted May 10, 2012 Author Posted May 10, 2012 <?php include_once('globals.php'); $user = (isset($_GET['u']) ? intval($_GET['u']) : FALSE; if(!$user) { echo 'No user selected!'; exit($h->endpage()); } $user = mysql_query('SELECT `userid`,`username` FROM `users` WHERE `userid` = '.$user); if(!mysql_num_rows($user)) { echo 'No user found!'; exit($h->endpage()); } $user = mysql_fetch_assoc($user); switch ($_GET['action']) { case 'plus_rate': do_plus_rating($user); break; case 'minus_rate': do_minus_rating($user); break; default: wrong(); break; } function wrong() { echo 'You have not selected to rate up or down!'; } function do_plus_rating($us) { if($us['userid'] == $_SESSION['userid']) { echo 'You can not rate yourself!'; } else { mysql_query('UPDATE `users` SET `prate` = (`prate` + 1) WHERE `userid` = '.$us['userid']); echo 'You have rated '.$u['useranme'].' up!<br /><a href="viewuser.php?u='.$us['userid'].'">Back</a>'; } } function do_minus_rating($us) { if($us['userid'] == $_SESSION['userid']) { echo 'You can not rate yourself!'; } else { mysql_query('UPDATE `users` SET `mrate` = (`mrate` + 1) WHERE `userid` = '.$us['userid']); echo 'You have rated '.$u['useranme'].' down!<br /><a href="viewuser.php?u='.$us['userid'].'">Back</a>'; } } $h->endpage(); ?> That gives me this: Parse error: syntax error, unexpected ';' in /home/district/public_html/ratings.php on line 20 All I changed was the header info to work with V1. Lines 17-22: $h->userdata($ir,$lv,$fm,$cm); $h->menuarea(); $user = (isset($_GET['u']) ? intval($_GET['u']) : FALSE; if(!$user) { echo 'No user selected!'; Quote
HauntedDawg Posted May 10, 2012 Posted May 10, 2012 Post up your hole code. Also, post up the link you go to when you rate up. You can hide your domain. Sorry thought you were using v2. Quote
Seker Posted May 10, 2012 Author Posted May 10, 2012 ratings.php: <?php session_start(); require "global_func.php"; if($_SESSION['loggedin']==0) { header("Location: login.php");exit; } $userid=$_SESSION['userid']; require "header.php"; $h = new headers; $h->startheaders(); include "mysql.php"; global $c; $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error()); $ir=mysql_fetch_array($is); check_level(); $fm=crystals_formatter($ir['crystals']); $cm=crystals_formatter($ir['crystals'],''); $lv=date('F j, Y, g:i a',$ir['laston']); $h->userdata($ir,$lv,$fm,$cm); $h->menuarea(); $user = (isset($_GET['u']) ? intval($_GET['u']) : FALSE; if(!$user) { echo 'No user selected!'; exit($h->endpage()); } $user = mysql_query('SELECT `userid`,`username` FROM `users` WHERE `userid` = '.$user); if(!mysql_num_rows($user)) { echo 'No user found!'; exit($h->endpage()); } $user = mysql_fetch_assoc($user); switch ($_GET['action']) { case 'plus_rate': do_plus_rating($user); break; case 'minus_rate': do_minus_rating($user); break; default: wrong(); break; } function wrong() { echo 'You have not selected to rate up or down!'; } function do_plus_rating($us) { if($us['userid'] == $_SESSION['userid']) { echo 'You can not rate yourself!'; } else { mysql_query('UPDATE `users` SET `prate` = (`prate` + 1) WHERE `userid` = '.$us['userid']); echo 'You have rated '.$u['useranme'].' up!<a href="viewuser.php?u='.$us['userid'].'">Back</a>'; } } function do_minus_rating($us) { if($us['userid'] == $_SESSION['userid']) { echo 'You can not rate yourself!'; } else { mysql_query('UPDATE `users` SET `mrate` = (`mrate` + 1) WHERE `userid` = '.$us['userid']); echo 'You have rated '.$u['useranme'].' down!<a href="viewuser.php?u='.$us['userid'].'">Back</a>'; } } $h->endpage(); ?> In viewuser: $rupp = mysql_query("SELECT prate FROM users WHERE prate={$r['userid']}", $c); $rup = mysql_num_rows($rupp); $rdownn = mysql_query("SELECT prate FROM users WHERE prate={$r['userid']}", $c); $rdown = mysql_num_rows($rdownn); Ratings: Up - <a href='ratings.php?action=plus_rate'>$rup</a> Down - <a href='ratings.php?action=minus_rate'>$rdown</a> Quote
HauntedDawg Posted May 10, 2012 Posted May 10, 2012 (edited) UPDATED CODE @ 03:33PM <?php session_start(); require_once('global_func.php'); if(!$_SESSION['loggedin']) { header('Location: login.php'); exit; } require_once('header.php'); $h = new headers(); $h->startheaders(); include_once('mysql.php'); $is = mysql_query('SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid='.intval($_SESSION['userid']), $c) or die(mysql_error()); $ir = mysql_fetch_assoc($is); check_level(); $fm = '$'.number_format($ir['money']); $cm = number_format($ir['crystals'); $lv = date('F j, Y, g:i a', $ir['laston']); $h->userdata($ir, $lv, $fm, $cm); $h->menuarea(); $user = isset($_GET['u']) ? intval($_GET['u']) : FALSE; if(!$user) { echo 'No user selected!'; exit($h->endpage()); } $user = mysql_query('SELECT `userid`,`username` FROM `users` WHERE `userid` = '.$user); if(!mysql_num_rows($user)) { echo 'No user found!'; exit($h->endpage()); } $user = mysql_fetch_assoc($user); switch ($_GET['action']) { case 'plus_rate': do_plus_rating($user); break; case 'minus_rate': do_minus_rating($user); break; default: wrong(); break; } function wrong() { echo 'You have not selected to rate up or down!'; } function do_plus_rating($us) { if($us['userid'] == $_SESSION['userid']) { echo 'You can not rate yourself!'; } else { mysql_query('UPDATE `users` SET `prate` = (`prate` + 1) WHERE `userid` = '.$us['userid']); echo 'You have rated '.$us['username'].' up!<a href="viewuser.php?u='.$us['userid'].'">Back</a>'; } } function do_minus_rating($us) { if($us['userid'] == $_SESSION['userid']) { echo 'You can not rate yourself!'; } else { mysql_query('UPDATE `users` SET `mrate` = (`mrate` + 1) WHERE `userid` = '.$us['userid']); echo 'You have rated '.$us['username'].' down!<a href="viewuser.php?u='.$us['userid'].'">Back</a>'; } } $h->endpage(); ?> Also, please change your links to this: Ratings: Up - <a href='ratings.php?action=plus_rate&u={$r['userid']}'>$rup</a> Down - <a href='ratings.php?action=minus_rate&u={$r['userid']}'>$rdown</a> Edited May 10, 2012 by HauntedDawg Quote
Seker Posted May 10, 2012 Author Posted May 10, 2012 Still getting this: Parse error: syntax error, unexpected ';' in /home/district/public_html/ratings.php on line 21 Doesn't really make sense to me, since that is: $user = (isset($_GET['u']) ? intval($_GET['u']) : FALSE; Quote
Seker Posted May 10, 2012 Author Posted May 10, 2012 (edited) ANOTHER EDIT: Working as far as, it does update the count in the DB, so thank you for that HD! Just not showing anything but "0" on the viewuser. Obviously just a display problem. I can figure that out. :P Then, I just need to add a check to see if $ir has alread rated $r. Thanks for the help! Edited May 10, 2012 by Seker Quote
HauntedDawg Posted May 10, 2012 Posted May 10, 2012 You will need a table to make the check to see if $ir has already rated $r. Also, i updated my code, i had $us['useranme'] instead of $us['username'] incase you've done changes to your side. I'll be busy here on out, so might not get a reply so fast anymore. Quote
Seker Posted May 10, 2012 Author Posted May 10, 2012 You will need a table to make the check to see if $ir has already rated $r. Also, i updated my code, i had $us['useranme'] instead of $us['username'] incase you've done changes to your side. I'll be busy here on out, so might not get a reply so fast anymore. Yep, thought it would be another table. :P Thanks again. Been tinkering with this for a bit, now. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.