javalopes Posted June 4, 2013 Share Posted June 4, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/278747-some-php-help-if-you-guys-dont-mind/ Share on other sites More sharing options...
cpd Posted June 4, 2013 Share Posted June 4, 2013 (edited) 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 June 4, 2013 by cpd Quote Link to comment https://forums.phpfreaks.com/topic/278747-some-php-help-if-you-guys-dont-mind/#findComment-1433942 Share on other sites More sharing options...
javalopes Posted June 4, 2013 Author Share Posted June 4, 2013 the users cant change the username. and i alredy try it alot but no luckim too noob on php im sory if im hasking too mutch Quote Link to comment https://forums.phpfreaks.com/topic/278747-some-php-help-if-you-guys-dont-mind/#findComment-1433946 Share on other sites More sharing options...
cpd Posted June 4, 2013 Share Posted June 4, 2013 Show us what you have and lets try and address your problems. No-one is going to write the code for you so forget about it. Quote Link to comment https://forums.phpfreaks.com/topic/278747-some-php-help-if-you-guys-dont-mind/#findComment-1433949 Share on other sites More sharing options...
Jessica Posted June 4, 2013 Share Posted June 4, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/278747-some-php-help-if-you-guys-dont-mind/#findComment-1434046 Share on other sites More sharing options...
javalopes Posted June 5, 2013 Author Share Posted June 5, 2013 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()); Quote Link to comment https://forums.phpfreaks.com/topic/278747-some-php-help-if-you-guys-dont-mind/#findComment-1434162 Share on other sites More sharing options...
Jessica Posted June 5, 2013 Share Posted June 5, 2013 What did the error say? Quote Link to comment https://forums.phpfreaks.com/topic/278747-some-php-help-if-you-guys-dont-mind/#findComment-1434169 Share on other sites More sharing options...
javalopes Posted June 5, 2013 Author Share Posted June 5, 2013 dont show any error just dont update the fields Quote Link to comment https://forums.phpfreaks.com/topic/278747-some-php-help-if-you-guys-dont-mind/#findComment-1434179 Share on other sites More sharing options...
DaveyK Posted June 5, 2013 Share Posted June 5, 2013 (edited) 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 June 5, 2013 by DaveyK Quote Link to comment https://forums.phpfreaks.com/topic/278747-some-php-help-if-you-guys-dont-mind/#findComment-1434181 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.