# PHP undefined variables in while loop

**URL:** <https://forum.kirupa.com/t/php-undefined-variables-in-while-loop/166463>\
**Category:** Uncategorized\
**Created:** [October 20, 2005, 3:28am UTC](https://forum.kirupa.com/t/php-undefined-variables-in-while-loop/166463 "2005-10-20T03:28:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dinkumrocks](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@dinkumrocks](https://forum.kirupa.com/u/dinkumrocks)\
**Post date:** [October 20, 2005, 3:28am UTC](https://forum.kirupa.com/t/php-undefined-variables-in-while-loop/166463/1 "2005-10-20T03:28:39Z")

</div>

hey guys. Im getting this error…

**Notice** : Undefined variable: user\_sites in **c:\Inetpub\wwwroot\adcore\earn\_top.php** on line **17**

**Warning** : mysql\_result(): supplied argument is not a valid MySQL result resource in **c:\Inetpub\wwwroot\adcore\earn\_top.php** on line **17**

**Notice** : Undefined variable: user\_sites in **c:\Inetpub\wwwroot\adcore\earn\_top.php** on line **18**

**Warning** : mysql\_result(): supplied argument is not a valid MySQL result resource in **c:\Inetpub\wwwroot\adcore\earn\_top.php** on line \*\*18

\*\*and this is my code…

```auto
11 $users_sites = mysql_query("select id,credits from sites where site_owner=".$_SESSION["uid"]." AND status=0;",$conn);
12 $reccount_user_sites = mysql_num_rows($users_sites);
13 if($reccount_user_sites >0) {
14 $divide_credits = $increment/$reccount_user_sites;
15 $reccount_get = 0;
16 while($reccount_user_sites > $reccount_get) {
17 $while_credits = mysql_result($user_sites,$reccount_get,"credits");
18 $while_id = mysql_result($user_sites,$reccount_get,"id");
19 $while_new_credits = $while_credits + $divide_credits;
20 mysql_query("UPDATE sites SET credits=".($while_new_credits/10)." WHERE id =".$while_id.";",$conn);
21 $reccount_get++;
22 }
23 }else{

```

I’m new to php, so dont be too mean 🙂

thanks for the help  
-Naaman
