Jump to content

Recommended Posts

<?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

<?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.";
}

}
?>

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?

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}";
}

}?>

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 =/

 

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 :P

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.