Jiraiya Posted December 16, 2008 Share Posted December 16, 2008 i have my script thats supposed to edit one variable if only if another variable is equal to or greater then 5 million but it dosnt seem to work here is the script <?php mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("members") or die(mysql_error()); $sql = mysql_query("SELECT * FROM users WHERE username = '$username'"); $row = mysql_fetch_array($sql); if($row['skill'] > 5000000){ mysql_query("UPDATE `users` SET `village` = 'Akatsuki' WHERE username = '$username'") or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137234-can-i-get-hand-please/ Share on other sites More sharing options...
Maq Posted December 16, 2008 Share Posted December 16, 2008 Where do you get $username from? You can just update it in 1 query. $sql = "UPDATE `users` SET `village` = 'Akatsuki' WHERE username = '$username' AND skill > 5000000"; mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/137234-can-i-get-hand-please/#findComment-716917 Share on other sites More sharing options...
Jiraiya Posted December 16, 2008 Author Share Posted December 16, 2008 its supposed to update a users variable Quote Link to comment https://forums.phpfreaks.com/topic/137234-can-i-get-hand-please/#findComment-716926 Share on other sites More sharing options...
Maq Posted December 16, 2008 Share Posted December 16, 2008 I asked where it comes from not what it's supposed to do... Can you post all of your code? Quote Link to comment https://forums.phpfreaks.com/topic/137234-can-i-get-hand-please/#findComment-716930 Share on other sites More sharing options...
Jiraiya Posted December 16, 2008 Author Share Posted December 16, 2008 is that right? $username = $_COOKIE['ID_my_site']; $sql = mysql_query("SELECT * FROM users WHERE username = '$username'"); $row = mysql_fetch_array($sql); if($row['skill'] > 5000000){ mysql_query("UPDATE `users` SET `village` = 'Akatsuki' WHERE username = '$username'") or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137234-can-i-get-hand-please/#findComment-717007 Share on other sites More sharing options...
revraz Posted December 16, 2008 Share Posted December 16, 2008 Sounds like your variables are empty. Have you echo'd them to see? Quote Link to comment https://forums.phpfreaks.com/topic/137234-can-i-get-hand-please/#findComment-717012 Share on other sites More sharing options...
premiso Posted December 16, 2008 Share Posted December 16, 2008 Where do you get $username from? You can just update it in 1 query. $sql = "UPDATE `users` SET `village` = 'Akatsuki' WHERE username = '$username' AND skill > 5000000"; mysql_query($sql) or die(mysql_error()); This is how you should do it, instead of 2 querys as stated. <?php if (isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $sql = "UPDATE `users` SET `village` = 'Akatsuki' WHERE username = '$username' AND skill > 5000000"; mysql_query($sql) or die(mysql_error()); } As long as there is a username in the cookie that should work. (I would store the username in session as appose to a cookie but yea.) Quote Link to comment https://forums.phpfreaks.com/topic/137234-can-i-get-hand-please/#findComment-717017 Share on other sites More sharing options...
Maq Posted December 16, 2008 Share Posted December 16, 2008 Yes, premiso provides the correct example of how you should perform this query. Also, as revraz stated, echo your variables to see what's inside. echo "query: " . $sql . " username: " . $username; Quote Link to comment https://forums.phpfreaks.com/topic/137234-can-i-get-hand-please/#findComment-717026 Share on other sites More sharing options...
Jiraiya Posted December 16, 2008 Author Share Posted December 16, 2008 this is what it displayed when i echoed it query: username: Quote Link to comment https://forums.phpfreaks.com/topic/137234-can-i-get-hand-please/#findComment-717036 Share on other sites More sharing options...
revraz Posted December 16, 2008 Share Posted December 16, 2008 Sounds like you have it in the wrong place, should be after your $sql variable $sql = "UPDATE `users` SET `village` = 'Akatsuki' WHERE username = '$username' AND skill > 5000000"; echo "query: " . $sql . "<br />username: " . $username; mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/137234-can-i-get-hand-please/#findComment-717041 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.