Log in

View Full Version : MySQL Field Not Updating


Rebecca217
10-12-2005, 02:11 AM
I'm trying to update a field called "credits" in the user table when a forum member posts a new thread. The code below runs with no PHP or MySQL errors, but the "credits" field isn't updated ($cost isn't subtracted).

Can anyone offer guidance on what I'm doing wrong?

Thanks!

Rebecca

// Critpoint cost of each critique

$cost = 2;

$critpoints = $vbulletin->userinfo['credits'];



if ($foruminfo['critforum'] == 1)

{

if($critpoints < $cost)

{

eval(standard_error(fetch_error('not_enough_critpo ints')));

}

else

{

$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user

SET credits = credits - $cost

WHERE userid = '$vbulletin->userinfo[userid]'

");

}

}



*EDITED*

Never mind. I figured this out. I'd been formatting the userid incorrectly in the last (quesry) section. In case this is useful to anyone else, here is the corrected/working code:



// Critpoint cost of each critique

$cost = 2;

$critpoints = $vbulletin->userinfo['credits'];



if ($foruminfo['critforum'] == 1)

{

if($critpoints < $cost)

{

eval(standard_error(fetch_error('not_enough_critpo ints')));

}

else

{

$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user

SET credits = credits - $cost

WHERE userid = '" . $vbulletin->userinfo['userid'] . "'

");

}

}

Hope this is helpful to someone else! :)

Rebecca