cdog5000 Posted June 28, 2008 Share Posted June 28, 2008 ok.. hard to explain.... i have a MYSQL database and a table named "FlaxerAuthAndSig" and i have 6 varibles.. the varible's are as follow 'username, password, id, amountOfFlax, amountOfFlaxPerHour,TotalHoursUsed' in that same order... but what i need it to do is get the 'TotalHoursUsed' of a user i select and add 1 hour but i cant seem to do that! best i came to was this. <?php mysql_connect('nothingtoseehere', 'nothing', 'thisisntapassword') or die(mysql_error ()); mysql_select_db('nothing') or die(mysql_error()); $user = $_GET['user']; $hours = $_GET['hours']; function getValues() { $sql = "SELECT TotalHoursUsed FROM FlaxerAuthAndSig WHERE username = '$user'"; return mysql_query($sql); } $tree = getValues(); mysql_query("INSERT INTO FlaxerAuthAndSig (TotalHoursUsed) VALUES('$tree') WHERE username = '$user'") ?> Quote Link to comment https://forums.phpfreaks.com/topic/112284-solved-inserting-into-mysql/ Share on other sites More sharing options...
.josh Posted June 28, 2008 Share Posted June 28, 2008 So you want to change the TotalHoursUsed to +1 more than it already is? update table set FlaxerAuthAndSig TotalHoursUsed = TotalHoursUsed+1 where username = '$user' Quote Link to comment https://forums.phpfreaks.com/topic/112284-solved-inserting-into-mysql/#findComment-576478 Share on other sites More sharing options...
cdog5000 Posted June 28, 2008 Author Share Posted June 28, 2008 So you want to change the TotalHoursUsed to +1 more than it already is? update table set FlaxerAuthAndSig TotalHoursUsed = TotalHoursUsed+1 where username = '$user' ok... now i have this: <?php mysql_connect('fdb1.runhosting.com', '126745_cdog', 'sports') or die(mysql_error ()); mysql_select_db('126745_cdog') or die(mysql_error()); $user = $_GET['user']; $hours = $_GET['hours']; if($user != null and $hours != null){ mysql_query("UPDATE TABLE SET FlaxerAuthAndSig TotalHoursUsed = TotalHoursUsed+1 WHERE username = '$user'"); echo "added time"; } ?> and dosent seem to add to totalHoursUsed Quote Link to comment https://forums.phpfreaks.com/topic/112284-solved-inserting-into-mysql/#findComment-576833 Share on other sites More sharing options...
.josh Posted June 28, 2008 Share Posted June 28, 2008 Assuming that your previous die(..) statements didn't echo any errors: - Add a die to your mysql_query see if it is returning an error for some reason. - Make sure table and column names are spelled right. - Echo out $user make sure it has what you expect it to have. - Make sure that there is indeed a username in the table called $user - Check your table in phpmyadmin or command line or w/e to see if it's updated there (because I don't see any code there that displays anything relevant) Quote Link to comment https://forums.phpfreaks.com/topic/112284-solved-inserting-into-mysql/#findComment-576839 Share on other sites More sharing options...
cdog5000 Posted June 28, 2008 Author Share Posted June 28, 2008 omg! still won't work!!!! here: <?php mysql_connect('fdb1.runhosting.com', '126745_cdog', 'sports') or die(mysql_error ()); mysql_select_db('126745_cdog') or die(mysql_error()); $user = $_GET['user']; $hours = $_GET['hours']; if($user != null and $hours != null){ echo $user; $current_Hours = mysql_query("SELECT TotalHoursUsed FROM FlaxerAuthAndSig WHERE username = '$user'"); mysql_query("UPDATE TABLE SET FlaxerAuthAndSig TotalHoursUsed = '$current_Hours'+1 WHERE username = '$user'"); echo "/n added time"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/112284-solved-inserting-into-mysql/#findComment-576855 Share on other sites More sharing options...
DeanWhitehouse Posted June 28, 2008 Share Posted June 28, 2008 Add a die statement to both your mysql_query Quote Link to comment https://forums.phpfreaks.com/topic/112284-solved-inserting-into-mysql/#findComment-576857 Share on other sites More sharing options...
cdog5000 Posted June 28, 2008 Author Share Posted June 28, 2008 ok.. Quote Link to comment https://forums.phpfreaks.com/topic/112284-solved-inserting-into-mysql/#findComment-576860 Share on other sites More sharing options...
cdog5000 Posted June 28, 2008 Author Share Posted June 28, 2008 cdog5000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TABLE SET FlaxerAuthAndSig TotalHoursUsed = 'Resource id #2'+1 WHERE username = ' at line 1 thats what i get! Quote Link to comment https://forums.phpfreaks.com/topic/112284-solved-inserting-into-mysql/#findComment-576862 Share on other sites More sharing options...
DeanWhitehouse Posted June 28, 2008 Share Posted June 28, 2008 i might be wrong but i think it should be mysql_query("UPDATE FlaxerAuthAndSig SET TotalHoursUsed = '$current_Hours'+1 WHERE username = '$user'"); Quote Link to comment https://forums.phpfreaks.com/topic/112284-solved-inserting-into-mysql/#findComment-576865 Share on other sites More sharing options...
.josh Posted June 28, 2008 Share Posted June 28, 2008 Okay first off, Blade is right, the actual table name needs to be there instead of TABLE. But 2nd, you don't need 2 separate queries to do that. You just need the update query. I mean think about it. You're selecting totalhoursused where username = '$user' and assigning it to a variable (which btw you did wrong: you just assigned a result source to $current_hours). Then you turn around and take that current number and update the row, adding 1 to that variable where username still equals $user. So take out the select query, you don't need it. <?php mysql_connect('fdb1.runhosting.com', '126745_cdog', 'sports') or die(mysql_error ()); mysql_select_db('126745_cdog') or die(mysql_error()); $user = $_GET['user']; $hours = $_GET['hours']; if($user != null and $hours != null){ echo $user; mysql_query("UPDATE FlaxerAuthAndSig SET TotalHoursUsed = TotalHoursUsed+1 WHERE username = '$user'"); echo "/n added time"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/112284-solved-inserting-into-mysql/#findComment-576870 Share on other sites More sharing options...
cdog5000 Posted June 28, 2008 Author Share Posted June 28, 2008 i might be wrong but i think it should be mysql_query("UPDATE FlaxerAuthAndSig SET TotalHoursUsed = '$current_Hours'+1 WHERE username = '$user'"); ty ty! Quote Link to comment https://forums.phpfreaks.com/topic/112284-solved-inserting-into-mysql/#findComment-576871 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.