cannot edit profile

Ask about a PHP problem here.
User avatar
leverkusen
Posts: 69
Joined: Sun Nov 18, 2012 10:09 pm
Location: Belgrade
Contact:

cannot edit profile

Post by leverkusen »

I cant edit profile, i think that id is not recognised
When i enter in edit.profile.php i get echo "Your profile has been updated! " and normal form without any editing instead of echo 'Click update to edit your profile.';
I dont have any errors or anything, maybe i should fetch user with something else or there is a problem in a code? Or i have to connect this with my login.php script?
edit.profile.php
[syntax=php]<?php

include('core/init.inc.php');
$errors = array();

if (empty($errors)){
$grad = htmlentities($_POST['grad']);
$drzava = htmlentities($_POST['drzava']);
$fan = htmlentities($_POST['fan']);
$website = htmlentities($_POST['website']);
$titles = htmlentities($_POST['titles']);





$user_info = array();
$user_info['grad'] = "$grad";
$user_info['drzava'] = "$drzava";
$user_info['fan'] = "$fan";
$user_info['website'] = "$website";
$user_info['titles'] = "$titles";
}else{
$user_info = fetch_user_info($_SESSION['uid']);
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Global Betting</title>
</head>
<body>
<div>
<?php

if (isset($errors) ==false){
echo 'Click update to edit your profile.';
}else if (empty($errors)){
echo 'Your profile has been updated!';
}else{
echo '<ul><li>'. implode('</li><li>'. $errors). '</li></ul>';
}

?>
</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method ="POST">
<div>
<label for="grad">Grad</label>
<input type="text" name="grad" id="grad" value="<?php echo $user_info['grad']; ?>" />
</div>
<div>
<label for="drzava">Drzava</label>
<input type="text" name="drzava" id="drzava" value="<?php echo $user_info ['drzava']; ?>" />
</div>
<div>
<label for="fan">Fan</label>
<input type="text" name="fan" id="fan" value="<?php echo $user_info ['fan']; ?>" />
</div>
<div>
<label for="grad">Website</label>
<input type="text" name="website" id="website" value="<?php echo $user_info ['website']; ?>" />
</div>
<div>
<label for="Titles">Titles</label>
<input type="titles" name="titles" id="titles" value="<?php echo $user_info ['titles']; ?>" />
</div>
<div>
<input type="submit" value="Update" />
</div>
</form>
</body>
</html>[/syntax]
Fidbeck
Posts: 147
Joined: Tue Sep 25, 2012 11:40 pm

Re: cannot edit profile

Post by Fidbeck »

Do you have the mysql UPDATE query?
User avatar
leverkusen
Posts: 69
Joined: Sun Nov 18, 2012 10:09 pm
Location: Belgrade
Contact:

Re: cannot edit profile

Post by leverkusen »

nooo
Fidbeck
Posts: 147
Joined: Tue Sep 25, 2012 11:40 pm

Re: cannot edit profile

Post by Fidbeck »

You might want to have one xD
User avatar
leverkusen
Posts: 69
Joined: Sun Nov 18, 2012 10:09 pm
Location: Belgrade
Contact:

Re: cannot edit profile

Post by leverkusen »

yea but i dont know how to post it properly, i tried to copy paste and edit from my changepassword.php script but its not good
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: cannot edit profile

Post by Temor »

Well, you set $errors at the top of the page, which means isset($errors) will always equal true, and since the array is in fact empty, the second if statement will be true.
What you might want to do is check to see if the form has been submitted before you set the $errors array.

[syntax=php]if(isset($_POST['name']){
$errors = array();
}[/syntax]
Fidbeck
Posts: 147
Joined: Tue Sep 25, 2012 11:40 pm

Re: cannot edit profile

Post by Fidbeck »

leverkusen wrote:yea but i dont know how to post it properly, i tried to copy paste and edit from my changepassword.php script but its not good

I'm not getting what you mean :S
User avatar
leverkusen
Posts: 69
Joined: Sun Nov 18, 2012 10:09 pm
Location: Belgrade
Contact:

Re: cannot edit profile

Post by leverkusen »

[syntax=php]<?php

include('core/init.inc.php');
if(isset($_POST['name']){
$errors = array();
}


if (empty($errors)){
$grad = htmlentities($_POST['grad']);
$drzava = htmlentities($_POST['drzava']);
$fan = htmlentities($_POST['fan']);
$website = htmlentities($_POST['website']);
$titles = htmlentities($_POST['titles']);





$user_info = array();
$user_info['grad'] = "$grad";
$user_info['drzava'] = "$drzava";
$user_info['fan'] = "$fan";
$user_info['website'] = "$website";
$user_info['titles'] = "$titles";
}else{
$user_info = fetch_user_info($_SESSION['uid']);
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Global Betting</title>
</head>
<body>
<div>
<?php

if (isset($errors) ==false){
echo 'Click update to edit your profile.';
}else if (empty($errors)){
echo 'Your profile has been updated!';
}else{
echo '<ul><li>'. implode('</li><li>'. $errors). '</li></ul>';
}

?>
</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method ="POST">
<div>
<label for="grad">Grad</label>
<input type="text" name="grad" id="grad" value="<?php echo $user_info['grad']; ?>" />
</div>
<div>
<label for="drzava">Drzava</label>
<input type="text" name="drzava" id="drzava" value="<?php echo $user_info ['drzava']; ?>" />
</div>
<div>
<label for="fan">Fan</label>
<input type="text" name="fan" id="fan" value="<?php echo $user_info ['fan']; ?>" />
</div>
<div>
<label for="grad">Website</label>
<input type="text" name="website" id="website" value="<?php echo $user_info ['website']; ?>" />
</div>
<div>
<label for="Titles">Titles</label>
<input type="titles" name="titles" id="titles" value="<?php echo $user_info ['titles']; ?>" />
</div>
<div>
<input type="submit" value="Update" />
</div>
</form>
</body>
</html>
[/syntax]

Parse error: syntax error, unexpected '{' in public_html/edit_profile.php on line 4
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: cannot edit profile

Post by Temor »

you need another closing parentheses here:
[syntax=php]if(isset($_POST['name']){[/syntax]
User avatar
leverkusen
Posts: 69
Joined: Sun Nov 18, 2012 10:09 pm
Location: Belgrade
Contact:

Re: cannot edit profile

Post by leverkusen »

ok now i need to put $mysql query for this changing, how should be right to put?
[syntax=php]$sql_mysql_query("update users set ='$grad' where uid = '$uid'");[/syntax]
is that right? and should i add else if before this?
Fidbeck
Posts: 147
Joined: Tue Sep 25, 2012 11:40 pm

Re: cannot edit profile

Post by Fidbeck »

[syntax=php]mysql_query("UPDATE `table` SET `field1` = '{$field1}', `field2` = '{$field2}' WHERE `id`='{$id}'");[/syntax]
this is inside a function

or you can simply
[syntax=php]$query = mysql_query("UPDATE `table` SET `field1` = '{$field1}', `field2` = '{$field2}' WHERE `id`='{$id}'");
print_r = $query;[/syntax]

I'm not sure so don't take my word for it
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: cannot edit profile

Post by ExtremeGaming »

Fidbeck wrote:or you can simply
[syntax=php]$query = mysql_query("UPDATE `table` SET `field1` = '{$field1}', `field2` = '{$field2}' WHERE `id`='{$id}'");
print_r = $query;[/syntax]


print_r is a php function and will give a syntax error the way you are using. As far as I see there is no reason why they would need to use print_r either. But I would suggest taking the advice here on the query.
<?php while(!$succeed = try()); ?>
User avatar
leverkusen
Posts: 69
Joined: Sun Nov 18, 2012 10:09 pm
Location: Belgrade
Contact:

Re: cannot edit profile

Post by leverkusen »

I added to my code that only logged users can see this page, thats why is now longer
When i edit profile i get echo 'Your profile has been succesfully updated!' but it makes no changes in phpmyadmin :roll:
is something missing? or wrong sessions?
[syntax=php] <?php

include('core/init.inc.php');
if(isset($_POST['grad'])){
$errors = array();
}
if(isset($_POST['drzava'])){
$errors = array();
}
if(isset($_POST['fan'])){
$errors = array();
}
if(isset($_POST['website'])){
$errors = array();
}

if (empty($errors)){
$grad = htmlentities($_POST['grad']);
$drzava = htmlentities($_POST['drzava']);
$fan = htmlentities($_POST['fan']);
$website = htmlentities($_POST['website']);





$user_info = array();
$user_info['grad'] = "$grad";
$user_info['drzava'] = "$drzava";
$user_info['fan'] = "$fan";
$user_info['website'] = "$website";
}else{
$user_info = fetch_user_info($_SESSION['uid']);
}

?>
<?php
mysql_query("UPDATE `users` SET `grad` = '{$grad}', `drzava` = '{$drzava}',`fan` = '{$fan}', `website` = '{$website}' WHERE `uid`='{$uid}'");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Global Betting</title>
</head>
<body>
<div>
<?php

if (isset($errors) ==false){
echo 'Click update to edit your profile.';
}else if (empty($errors)){
echo 'Your profile has been updated!';
}else{
echo '<ul><li>'. implode('</li><li>'. $errors). '</li></ul>';
}

?>
<?php
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
{
?>
</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method ="POST">
<div>
<label for="grad">Grad</label>
<input type="text" name="grad" id="grad" value="<?php echo $user_info['grad']; ?>" />
</div>
<div>
<label for="drzava">Drzava</label>
<input type="text" name="drzava" id="drzava" value="<?php echo $user_info ['drzava']; ?>" />
</div>
<div>
<label for="fan">Fan</label>
<input type="text" name="fan" id="fan" value="<?php echo $user_info ['fan']; ?>" />
</div>
<div>
<label for="grad">Website</label>
<input type="text" name="website" id="website" value="<?php echo $user_info ['website']; ?>" />
</div>
<div>
<input type="submit" value="Update" />
</div>
</form>
</body>
</html>
<?php
}
elseif(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = md5(mysql_real_escape_string($_POST['password']));

$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");

if(mysql_num_rows($checklogin) == 1)
{
$row = mysql_fetch_array($checklogin);

$_SESSION['Username'] = $username;
$_SESSION['uid'] = 1;

echo "<h1><center>Success</center></h1>";
echo "<p><center>We are now redirecting you to the member area.</center></p>";
echo "<meta http-equiv='refresh' content='=2;user.php' />";
}
else
{
echo "<h1>Error</h1>";
echo "<p>Sorry, your account could not be found. Please <a href=\"user.php\">click here to try again</a>.</p>";
}
}
else
{
?>
<?php
}
?>[/syntax]
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: cannot edit profile

Post by ExtremeGaming »

I don't see anywhere that you are generating $uid from. Add echo mysql_error() after your update query like this

[syntax=php]mysql_query("UPDATE `users` SET `grad` = '{$grad}', `drzava` = '{$drzava}',`fan` = '{$fan}', `website` = '{$website}' WHERE `uid`='{$uid}'");
echo mysql_error();[/syntax]
<?php while(!$succeed = try()); ?>
User avatar
leverkusen
Posts: 69
Joined: Sun Nov 18, 2012 10:09 pm
Location: Belgrade
Contact:

Re: cannot edit profile

Post by leverkusen »

i dont have any errors when i want to edit :cry:
User avatar
leverkusen
Posts: 69
Joined: Sun Nov 18, 2012 10:09 pm
Location: Belgrade
Contact:

Re: cannot edit profile

Post by leverkusen »

code is fine o smth is missing?
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: cannot edit profile

Post by Temor »

Well, this code [syntax=php]<?php
mysql_query("UPDATE `users` SET `grad` = '{$grad}', `drzava` = '{$drzava}',`fan` = '{$fan}', `website` = '{$website}' WHERE `uid`='{$uid}'");
?>[/syntax]

is out of place.

go back and watch the tutorial again and you'll see where to put this.
User avatar
leverkusen
Posts: 69
Joined: Sun Nov 18, 2012 10:09 pm
Location: Belgrade
Contact:

Re: cannot edit profile

Post by leverkusen »

[syntax=php]<?php


function fetch_users (){
$result = mysql_query('SELECT `uid` AS `id`, `username` AS `username` FROM `users`');


$users = array();

while (($row = mysql_fetch_assoc($result)) != false){
$users[] = $row;
}

return $users;
}


function fetch_user_info($uid){
$uid = (int)$uid;

$sql = "SELECT
`username` AS `username`,
`grad` AS `grad`,
`drzava` AS `drzava`,
`fan` AS `fan`,
`Website` AS `Website`
FROM users
WHERE `uid` = '$uid'";

$result = mysql_query($sql);

return mysql_fetch_assoc($result);
}

function set_profile_info($username, $grad, $drzava, $fan, $website){
$username = mysql_real_escape_string(htmlentities($username));
$grad = mysql_real_escape_string(htmlentities($grad));
$drzava = mysql_real_escape_string(htmlentities($drzava));
$fan = mysql_real_escape_string(htmlentities($fan));
$website = mysql_real_escape_string(htmlentities($website));
$uid = $_SESSION['uid'];

mysql_query("UPDATE `users` SET `username` = '($username)', `grad` = '{$grad}', `drzava` = '{$drzava}',`fan` = '{$fan}', `website` = '{$website}' WHERE `uid`='{$uid}'");
}


?>[/syntax]
its in here
mysql_query("UPDATE `users` SET `username` = '($username)', `grad` = '{$grad}', `drzava` = '{$drzava}',`fan` = '{$fan}', `website` = '{$website}' WHERE `uid`='{$uid}'");
i did echo for mysql error but nothing appears
maybe i have wrong sessions?
User avatar
leverkusen
Posts: 69
Joined: Sun Nov 18, 2012 10:09 pm
Location: Belgrade
Contact:

Re: cannot edit profile

Post by leverkusen »

hmm no solution? :?
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: cannot edit profile

Post by ExtremeGaming »

You have parentheses around $username I don't think it matters but might be worth changing.

I believe Temor is on to something as well.
<?php while(!$succeed = try()); ?>
User avatar
leverkusen
Posts: 69
Joined: Sun Nov 18, 2012 10:09 pm
Location: Belgrade
Contact:

Re: cannot edit profile

Post by leverkusen »

well i removed them but nothing
[syntax=php] mysql_query("UPDATE `users` SET `username` = `$username`, `grad` = `$grad`, `drzava` = `$drzava`,`fan` = `$fan`, `website` = `$website` WHERE `uid`=`$uid`");
}[/syntax]
Post Reply