Page 1 of 5
cannot edit profile
Posted: Tue Nov 27, 2012 6:04 pm
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
<?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>
Re: cannot edit profile
Posted: Tue Nov 27, 2012 6:07 pm
by Fidbeck
Do you have the mysql UPDATE query?
Re: cannot edit profile
Posted: Tue Nov 27, 2012 6:21 pm
by leverkusen
nooo
Re: cannot edit profile
Posted: Tue Nov 27, 2012 6:27 pm
by Fidbeck
You might want to have one xD
Re: cannot edit profile
Posted: Tue Nov 27, 2012 6:32 pm
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
Re: cannot edit profile
Posted: Tue Nov 27, 2012 6:41 pm
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.
if(isset($_POST['name']){
$errors = array();
}
Re: cannot edit profile
Posted: Tue Nov 27, 2012 6:43 pm
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
Re: cannot edit profile
Posted: Tue Nov 27, 2012 9:10 pm
by leverkusen
<?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>
Parse error: syntax error, unexpected '{' in public_html/edit_profile.php on line 4
Re: cannot edit profile
Posted: Tue Nov 27, 2012 10:03 pm
by Temor
you need another closing parentheses here:
if(isset($_POST['name']){
Re: cannot edit profile
Posted: Wed Nov 28, 2012 12:40 am
by leverkusen
ok now i need to put $mysql query for this changing, how should be right to put?
$sql_mysql_query("update users set ='$grad' where uid = '$uid'");
is that right? and should i add else if before this?
Re: cannot edit profile
Posted: Wed Nov 28, 2012 12:44 am
by Fidbeck
mysql_query("UPDATE `table` SET `field1` = '{$field1}', `field2` = '{$field2}' WHERE `id`='{$id}'");
this is inside a function
or you can simply
$query = mysql_query("UPDATE `table` SET `field1` = '{$field1}', `field2` = '{$field2}' WHERE `id`='{$id}'");
print_r = $query;
I'm not sure so don't take my word for it
Re: cannot edit profile
Posted: Wed Nov 28, 2012 1:04 am
by ExtremeGaming
Fidbeck wrote:
or you can simply
$query = mysql_query("UPDATE `table` SET `field1` = '{$field1}', `field2` = '{$field2}' WHERE `id`='{$id}'");
print_r = $query;
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.
Re: cannot edit profile
Posted: Wed Nov 28, 2012 1:29 am
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
is something missing? or wrong sessions?
<?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
}
?>
Re: cannot edit profile
Posted: Wed Nov 28, 2012 3:34 am
by ExtremeGaming
I don't see anywhere that you are generating $uid from. Add echo mysql_error() after your update query like this
mysql_query("UPDATE `users` SET `grad` = '{$grad}', `drzava` = '{$drzava}',`fan` = '{$fan}', `website` = '{$website}' WHERE `uid`='{$uid}'");
echo mysql_error();
Re: cannot edit profile
Posted: Wed Nov 28, 2012 11:46 pm
by leverkusen
i dont have any errors when i want to edit
Re: cannot edit profile
Posted: Thu Nov 29, 2012 11:17 pm
by leverkusen
code is fine o smth is missing?
Re: cannot edit profile
Posted: Fri Nov 30, 2012 4:55 am
by Temor
Well, this code
<?php
mysql_query("UPDATE `users` SET `grad` = '{$grad}', `drzava` = '{$drzava}',`fan` = '{$fan}', `website` = '{$website}' WHERE `uid`='{$uid}'");
?>
is out of place.
go back and watch the tutorial again and you'll see where to put this.
Re: cannot edit profile
Posted: Fri Nov 30, 2012 2:41 pm
by leverkusen
<?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}'");
}
?>
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?
Re: cannot edit profile
Posted: Tue Dec 04, 2012 7:17 am
by leverkusen
hmm no solution?
Re: cannot edit profile
Posted: Tue Dec 04, 2012 1:02 pm
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.
Re: cannot edit profile
Posted: Tue Dec 04, 2012 11:08 pm
by leverkusen
well i removed them but nothing
mysql_query("UPDATE `users` SET `username` = `$username`, `grad` = `$grad`, `drzava` = `$drzava`,`fan` = `$fan`, `website` = `$website` WHERE `uid`=`$uid`");
}