Foser Posted August 7, 2007 Share Posted August 7, 2007 <?php if (isset($_POST['settings_submit'])){ mysql_query("UPDATE user_info SET email = '$_POST[settings_email]', location = '$_POST[settings_location]', avatar_url = '$_POST[settings_avatar]', url = $_POST[settings_webpage]' WHERE username = '$_SESSION[uSERNAME]'"); echo "Information Successfully updated."; } ?> this just does not update.. I would also like to do, if the query was successfully sent to do the last echo... Not completely sure how to do that thanks Link to comment https://forums.phpfreaks.com/topic/63674-solved-update-not-updating/ Share on other sites More sharing options...
play_ Posted August 7, 2007 Share Posted August 7, 2007 <?php if (isset($_POST['settings_submit'])){ $email = $_POST['settings_email']; $location = $_POST['settings_location']; $avatar_url = $_POST['settings_avatar']; $url = $_POST['settings_webpage']; $username = $_SESSION['USERNAME']; $query = "UPDATE user_info SET email = '$email', location = '$location', avatar_url = '$avatar_url', url = '$url' WHERE username = '$username')"; $result = mysql_query($query); if($result) { echo "Information Successfully updated."; } } ?> Link to comment https://forums.phpfreaks.com/topic/63674-solved-update-not-updating/#findComment-317329 Share on other sites More sharing options...
Daniel0 Posted August 7, 2007 Share Posted August 7, 2007 Or change mysql_query("UPDATE user_info SET email = '$_POST[settings_email]', location = '$_POST[settings_location]', avatar_url = '$_POST[settings_avatar]', url = $_POST[settings_webpage]' WHERE username = '$_SESSION[uSERNAME]'"); to mysql_query("UPDATE user_info SET email = '{$_POST['settings_email']}', location = '{$_POST['settings_location']}', avatar_url = '{$_POST['settings_avatar']}', url = '{$_POST['settings_webpage']}' WHERE username = '{$_SESSION['USERNAME']}'"); Do you understand those changes and why it'll work while yours won't? Do you understand why e.g. <?php $array = array( array( 'type' => 1, 'name' => 'hi', ), array( 'type' => 2, 'name' => 'hello', ), ); echo "$array[0]['name']"; ?> will output Array['name'] and not hi? Link to comment https://forums.phpfreaks.com/topic/63674-solved-update-not-updating/#findComment-317349 Share on other sites More sharing options...
Foser Posted August 7, 2007 Author Share Posted August 7, 2007 Now I try to do a password changer with your tsyle of updating but it says it updates it, but it shows a blank in the database... <?php if (isset($_POST['pw_submit'])){ $password = $_POST['settings_pw']; $pw = $_POST['settings_pw']; $encryt_pw = md5($_POST['settings_pw']); $username = $_SESSION['USERNAME']; $query = "UPDATE user_info SET password = '{$encrypt_pw}' WHERE username = '{$username}'"; $result = mysql_query($query); $result; if ($result){ echo "Your New password is: {$pw}"; } }?> Link to comment https://forums.phpfreaks.com/topic/63674-solved-update-not-updating/#findComment-317354 Share on other sites More sharing options...
Daniel0 Posted August 7, 2007 Share Posted August 7, 2007 It's because you defined it as $encrypt_pw without a "p". Link to comment https://forums.phpfreaks.com/topic/63674-solved-update-not-updating/#findComment-317357 Share on other sites More sharing options...
play_ Posted August 7, 2007 Share Posted August 7, 2007 Do you understand those changes and why it'll work while yours won't? Do you understand why e.g. <?php $array = array( array( 'type' => 1, 'name' => 'hi', ), array( 'type' => 2, 'name' => 'hello', ), ); echo "$array[0]['name']"; ?> will output Array['name'] and not hi? Explain that to me though, cause i don't =/ Link to comment https://forums.phpfreaks.com/topic/63674-solved-update-not-updating/#findComment-317531 Share on other sites More sharing options...
Daniel0 Posted August 7, 2007 Share Posted August 7, 2007 Explain that to me though, cause i don't =/ Okay It is sort of explained here. The curly brackets are required when using multi-dimensional arrays (i.e. when accessing arrays using multiple indexes). When inside the string PHP will see $array[0] and says "Hey, that's a variable!" so it'll parse it. When echoing only $array[0] (which is an array/contains an array) Array will be output. Then there is the remaining ['name'] which PHP doesn't recognize as anything special and ignores it. That results in Array['name']. I've made it a habbit of always enclosing variables in curly brackets (except of course when I'm outside a string). I hope that was a good enough explanation because I can't do it better Link to comment https://forums.phpfreaks.com/topic/63674-solved-update-not-updating/#findComment-317549 Share on other sites More sharing options...
play_ Posted August 7, 2007 Share Posted August 7, 2007 Haha yes, good enough. thanks =) Link to comment https://forums.phpfreaks.com/topic/63674-solved-update-not-updating/#findComment-317552 Share on other sites More sharing options...
Crow Posted August 7, 2007 Share Posted August 7, 2007 Basically the curly-brackets mean, "evaluate me first". If you look at it like a math equation: 2(3+4) = 14 as opposed to 2(3)+4 = 10. The parenthesis tell the person doing the math to evaluate the 3+4 first, that's what the {} does with PHP. Link to comment https://forums.phpfreaks.com/topic/63674-solved-update-not-updating/#findComment-317553 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.