pgrevents Posted May 25, 2009 Share Posted May 25, 2009 Hi again hit a stumbling block for some reason my mysql wont update. It is an email activation code and I know that the variables are getting passed as there is an if statement verifying that there is a result based on variables passed here is the php code <?php // Grab url get $accode = $_GET['code']; $em = $_GET['email']; $un = $_GET['username']; //CONNECTION include('../always/comms/data.php'); mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to database'); $dbname = 'iam_user'; mysql_select_db($dbname); $query = "SELECT * FROM activation WHERE ac = '$accode' AND email = '$em' "; $loginres = mysql_query($query); $numrows = mysql_num_rows($loginres); if ($numrows > 0) { mysql_query("UPDATE user_name SET active = 'yes' WHERE iamlink = '$accode' AND username = '$un' AND email = '$em' "); mysql_query("UPDATE activtion SET activated = 'yes' WHERE ac = '$accode' AND email = '$em'"); header('Location:../registration/?reg=choose'); } else { header('Location:../registration/?reg=wrongcode'); } ?> Any suggestions? thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/ Share on other sites More sharing options...
kevinkorb Posted May 25, 2009 Share Posted May 25, 2009 Change Your Updates to Selects to make sure that you're getting rows to update. That should then be able to figure out where your problem lies. Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841933 Share on other sites More sharing options...
pgrevents Posted May 25, 2009 Author Share Posted May 25, 2009 dont quite understand that but changed update to select on both querys and still no change ??? Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841937 Share on other sites More sharing options...
kevinkorb Posted May 25, 2009 Share Posted May 25, 2009 Clarify a little more what you expect to happen, and what is happening in more detail. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841938 Share on other sites More sharing options...
kevinkorb Posted May 25, 2009 Share Posted May 25, 2009 Try this and see if it helps you out. <code> <?php // Grab url get $accode = $_GET['code']; $em = $_GET['email']; $un = $_GET['username']; //CONNECTION include('../always/comms/data.php'); mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to database'); $dbname = 'iam_user'; mysql_select_db($dbname); $query = "SELECT * FROM activation WHERE ac = '$accode' AND email = '$em' "; $loginres = mysql_query($query); $numrows = mysql_num_rows($loginres); if ($numrows > 0) { $result =mysql_query("UPDATE user_name SET active = 'yes' WHERE iamlink = '$accode' AND username = '$un' AND email = '$em' "); echo mysql_affected_rows($result)." Affected rows for $accode - $un - $em"; $result = mysql_query("UPDATE activtion SET activated = 'yes' WHERE ac = '$accode' AND email = '$em'"); echo mysql_affected_rows($result)." Affected rows for Activation $accode - $em"; //header('Location:../registration/?reg=choose'); } else { //header('Location:../registration/?reg=wrongcode'); } ?> </code> Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841941 Share on other sites More sharing options...
pgrevents Posted May 25, 2009 Author Share Posted May 25, 2009 Sure What is happening is users who have signed up get an activation email they click on the link and the link brings them to this page. Now the script grabs the data from the url and then checks if it is an actual actual code. That is where the first SELECT query is used. If there is a code then i want it to update the user_name and set active to yes (plays part of the login script) and sets activation table to yes so if a user trys to activate again then the user is taken to a page that says already activated etc (not done that part yet) So I am trying to update 2 tables Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841942 Share on other sites More sharing options...
kevinkorb Posted May 25, 2009 Share Posted May 25, 2009 Another thing you need to look out for is escaping your data. Since you're getting data from the user $_GET etc. Escape that using... $accode = mysql_real_escape_data($_GET['code']); $em = mysql_real_escape_data($_GET['email']); $un = mysql_real_escape_data($_GET['username']); Then they can't use 'SQL Injection' Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841944 Share on other sites More sharing options...
pgrevents Posted May 25, 2009 Author Share Posted May 25, 2009 i used your code and got a print out of the variables i am trying to pass output; Affected rows for 37e48acbb43dda0568b8867381227f12 - testusername - testemail Affected rows for Activation 37e48acbb43dda0568b8867381227f12 - testemail ps i am not a programmer by any sorts just trying to do what i can Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841945 Share on other sites More sharing options...
kevinkorb Posted May 25, 2009 Share Posted May 25, 2009 It is saying that it's not updating your rows. Check your user_name table to make sure that it has those values. SELECT * FROM user_name WHERE iamlink = '37e48acbb43dda0568b8867381227f12' AND username = 'testusername' AND email = 'testemail' When you run this, do you get any rows back? Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841948 Share on other sites More sharing options...
pgrevents Posted May 25, 2009 Author Share Posted May 25, 2009 see i thought that but its in an if statement that checks to see if there is a row with those details there. i have tested it with values in the table and values that arent in the table and the if statement works which leads me to think that the details in the update are correct Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841950 Share on other sites More sharing options...
kevinkorb Posted May 25, 2009 Share Posted May 25, 2009 Your select doesn't check the username though.... Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841952 Share on other sites More sharing options...
pgrevents Posted May 25, 2009 Author Share Posted May 25, 2009 true just checked my spelling on the update activation it was wrong changed that now that works but update user_name i will have another bash Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841953 Share on other sites More sharing options...
kevinkorb Posted May 25, 2009 Share Posted May 25, 2009 Try this: $result =mysql_query("UPDATE user_name SET active = 'yes' WHERE iamlink = '$accode' AND username = '$un' AND email = '$em' ") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841956 Share on other sites More sharing options...
pgrevents Posted May 25, 2009 Author Share Posted May 25, 2009 i found it wrong letter changed it it now works. thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841958 Share on other sites More sharing options...
gnawz Posted May 25, 2009 Share Posted May 25, 2009 try putting variables lie you did on the select $loginres = mysql_query($query); $numrows = mysql_num_rows($loginres); else, tell us what error(s) you get. If it is a blank page, check if your form(s) and code have the same variables, ie $_GET or $_POST and/or your database table names Quote Link to comment https://forums.phpfreaks.com/topic/159626-solved-update-mystery/#findComment-841961 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.