Jump to content

Some php help if you guys dont mind


javalopes

Recommended Posts

Hi guys.

Im starting an online webpage.

I recently have some sql/php doubts.

I need the php-sql code for this situation:

- Table:

          users

              - balance

              - refered - (person who refered the current logged in user - aka "referals")

              - username.


When certain user do an action. The sql should see his/her refered person.

Then when the user get the usally +balance for doing an action his/her refered should be credited to.


User -> Action -> User balance = balance + (x) -> refered balance + (y).


I enter an following img atachment to explain it.




Very gratefull for your time/help :)



83950286.gif









 

Link to comment
Share on other sites

What happens if the user changes their username? If username is unique and will never change, why don't you use it as the primary key?

 

What have you attempted yourself? We're not about to write the code for you which is why your post implies you think?

Edited by cpd
Link to comment
Share on other sites

Best practice is to use an auto-incrementing id as your primary key, even if you think usernames will never change.

 

OP: You haven't posted a question or a problem or any code. You've just posted what you want to happen. Cool story.

Link to comment
Share on other sites

i have made this code but still not working some 1 can see whats wrong?

 

 

//        ----------------------------------- REFERALS ---------------------------------
 
 
// Get refered
 
$query = ("UPDATE user SET referalsearns=referalsearns+".$referalsearns. " WHERE refered='" .$refered. "'");
mysql_query($query) or die('Query "' . $query . '" failed: ' . mysql_error());

 
// Update Balance
 
$query = ("UPDATE user SET balance=balance+".$currency. " WHERE username='" .$username. "'");
mysql_query($query) or die('Query "' . $query . '" failed: ' . mysql_error());

Link to comment
Share on other sites

Are you sure the queries run in the first place?

 

Try echoing something or perhaps (for development):

$q= mysql_query($query);

if ($q!== false)
{
  echo 'query was succesful';
}
else
{
  die('Query "' . $q. '" failed: ' . mysql_error())
}

the difference between what you do and what I describe above is that you always get a confirmation that the query actually did something. In your case, if you dont see an error you just assume that the query ran. Perhaps it doesnt even go that far in your script because of a previous error.

 

Also:

echo mysql_affected_rows(); // This will tell you how many rows were affected, or updated in this case.
Edited by DaveyK
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.