Forum Moderators: coopster
So, I do a search for an active record (some records are not active) that has 0 in the credits column.
That works great. However, when it updates the credits, it updates all the active records, not just the one specified in the UPDATE query.
each record has a unique "mid" that I used to try to make sure it only updates that one record but it is not working.
Any help would be great. here is the code:
<?
include ("config/db_config.php");$found_ad = mysql_query("SELECT * FROM jx_members WHERE status = 'active' and credits = 0 LIMIT 1");
if (found_ad){
while ($found = mysql_fetch_array($found_ad)){
$dude = $found['mid'];
$url = $found['custom_field_value_1'];
$pic = $found['custom_field_value_2'];
}
$add_cred_now = mysql_query("UPDATE jx_members SET credits = 1 WHERE mid = '".$dude."' LIMIT 1");
if($add_cred_now){
?>
Display here works fine...
<?
}
}
else {
$all_done = mysql_query("UPDATE jx_members SET credits = 0 WHERE status = 'active'");
if($all_done){
$found_ad = mysql_query("SELECT * FROM jx_members WHERE status = 'active' and credits = 0 LIMIT 1");
while ($found = mysql_fetch_array($found_ad)){
$dude = $found['mid'];
$url = $found['custom_field_value_1'];
$pic = $found['custom_field_value_2'];
}
$add_cred_now = mysql_query("UPDATE jx_members SET credits = 1 WHERE mid = '".$dude."' LIMIT 1");
if($add_cred_now){
?>
Display here works fine...
<?
}
}
else {
echo "Error 5546";
}
}
?>
I think most of your problem is here on your third line:
if (found_ad){
You need a dollar sign in front of the variable name.
While you're debugging a script you might find it helpful to have at the top:
error_reporting(E_ALL);
Which causes it to report errors like that one.
Not a problem but as a side note, when you're only retrieving one record you don't need a while loop:
while ($found = mysql_fetch_array($found_ad)){
becomes simply:
$found = mysql_fetch_array($found_ad);