View Full Version : $var = $var unexpected result
Thr33
03-18-2017, 12:39 PM
I run a vBulletin plugin that has always worked fine until recently i upgraded Apache and PHP from 5.4 to 5.5 and suddonly a calculation isnt working the way it should do:
$RUser = $row2['reputation'];
$RUserMinus = $RUser-1;
Instead of $RuserMinus being the result of $Ruser -1 it's replacing the value with -1 so $RUserMinus = "-1" instead of the result.
FULL SCRIPT
$query2 = $db->query_read("SELECT reputation FROM user WHERE userid =" . $vbulletin->userinfo['userid']) or die(mysql_error());
while($row2 = mysql_fetch_array( $query2 )) {
$RUser = $row2['reputation'];
}
$RUserMinus = $RUser-1;
$vbulletin->db->query_write("UPDATE user SET reputation=".$RUserMinus." WHERE userid=".$vbulletin->userinfo['userid']) or die (mysql_error());
}
Try
$RUserMinus = ($RUser - 1);
Thr33
03-18-2017, 01:37 PM
Same result, changes the value to -1
Try
$RUserMinus = ($RUser - 1);
MarkFL
03-18-2017, 02:25 PM
Try putting the statement:
$RUserMinus = $RUser-1;
within the while loop. :)
Thr33
03-18-2017, 02:37 PM
Database Error
]]> Database error in vBulletin 4.2.3
Invalid SQL: UPDATE user SET reputation= WHERE userid=2;
MySQL Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE userid=2' at line 1
Error Number : 1064
Request Date : Saturday, March 18th 2017 @ 03:37:01 PM
Error Date : Saturday, March 18th 2017 @ 03:37:01 PM
Script : http://literecords.com/sandbox/post_thanks.php
Referrer : http://literecords.com/sandbox/showthread.php?2-rep-test
Classname : vB_Database_MySQLi
MySQL Version : 5.5.54-cll
]]>
MarkFL
03-18-2017, 02:46 PM
Rather than use a db query to get the browsing user's reputation, I would simply use:
$vbulletin->userinfo['reputation']
Thus, your code becomes:
$RUserMinus = $vbulletin->userinfo['reputation'] - 1;
$vbulletin->db->query_write("UPDATE user SET reputation=" . $RUserMinus . " WHERE userid=".$vbulletin->userinfo['userid']) or die (mysql_error());
Thr33
03-18-2017, 02:51 PM
Im not sure if that work as i use 2 queries in the full plugin script is:
if ($vbulletin->userinfo['userid'] !== $threadinfo['postuserid'])
{
$query = $db->query_read("SELECT reputation FROM user WHERE userid =" . $threadinfo['postuserid']) or die(mysql_error());
while($row = mysql_fetch_array( $query )) {
$OPRep = $row['reputation'];
$OPRepPlus = $OPRep+1; }
$vbulletin->db->query_write("UPDATE user SET reputation=".$OPRepPlus." WHERE userid=".$threadinfo['postuserid']) or die (mysql_error());
$query2 = $db->query_read("SELECT reputation FROM user WHERE userid =" . $vbulletin->userinfo['userid']) or die(mysql_error());
while($row2 = mysql_fetch_array( $query2 )) {
$RUser = $row2['reputation'];
$RUserMinus = $RUser-1; }
$vbulletin->db->query_write("UPDATE user SET reputation=".$RUserMinus." WHERE userid=".$vbulletin->userinfo['userid']) or die (mysql_error());
}
else
{
}
--------------- Added 1489852566 at 1489852566 ---------------
AHHHH it f*cking works!! You absolute legend! Do you make music? I'll give you a privileged account haha!
--------------- Added 1489852778 at 1489852778 ---------------
When i did it for the -1 part it worked great but when i adapted to the +1 part it give me the same database error as earlier ^^
if ($vbulletin->userinfo['userid'] !== $threadinfo['postuserid'])
{
$OPRepPlus = $vbulletin->userinfo['reputation'] + 1;
$vbulletin->db->query_write("UPDATE user SET reputation=".$OPRepPlus." WHERE userid=".$threadinfo['postuserid']) or die (mysql_error());
$RUserMinus = $vbulletin->userinfo['reputation'] - 1;
$vbulletin->db->query_write("UPDATE user SET reputation=".$RUserMinus." WHERE userid=".$vbulletin->userinfo['userid']) or die (mysql_error());
}
else
{
}
--------------- Added 1489853144 at 1489853144 ---------------
$vbulletin->userinfo['reputation']
I think i see the problem. This line grabs the replying member's reputation. I need to find the thread starter's reputation.
--------------- Added 1489853318 at 1489853318 ---------------
It's deducting -1 from thread starter's reputation instead of +1
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.