I have changed the script a little and now I am not getting any messages. When I click update, the form empties and in the database; user_email is set to 0 and the country remains the same. I have decided to add all of the relavent source code this time.
dbc.php
PHP Code:
<?php
$dbname = '****';
$link = mysql_connect("localhost","*****","*****") or die("Couldn't make connection.");
$db = mysql_select_db($dbname, $link) or die("Couldn't select database");
$user_name = $_SESSION['user'];
?>
php code from login.php
PHP Code:
<?php
session_start();
?>
<?php
if (isset($_SESSION['user'])) {
header("Location: secure.php"); }
?>
<?php
include 'dbc.php';
$user_name = mysql_real_escape_string($_POST['name']);
if ($_POST['Submit']=='Prijava')
{
$md5pass = md5($_POST['pwd']);
$sql = "SELECT id,user_name,user_email,country FROM users WHERE
user_name = '$user_name' AND
user_pwd = '$md5pass' AND user_activated='1'";
$result = mysql_query($sql) or die (mysql_error());
$num = mysql_num_rows($result);
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
session_start();
list($user_id,$user_name,$user_email,$country) = mysql_fetch_row($result);
// this sets variables in the session
$_SESSION['user_email']= $user_email AND $_SESSION['country']= $country AND $_SESSION['user']= $user_name AND $_SESSION['user_id']= $id;
if (isset($_GET['ret']) && !empty($_GET['ret']))
{
header("Location: $_GET[ret]");
} else
{
header("Location: secure.php");
}
//echo "Logged in...";
exit();
}
header("Location: login.php?pogreska");
exit();
}
?>
settings.php
PHP Code:
<?php
session_start();
if (!isset($_SESSION['user']))
{
header("Location: login.php");
}
include ('dbc.php');
if ($_POST['Submit']=='Change')
{
$rsPwd = mysql_query("select user_pwd from users where user_name='$_SESSION[user]'") or die(mysql_error());
list ($oldpwd) = mysql_fetch_row($rsPwd);
if ($oldpwd == md5($_POST['oldpwd']))
{
$newpasswd = md5($_POST['newpwd']);
mysql_query("Update users
SET user_pwd = '$newpasswd'
WHERE user_name = '$_SESSION[user]'
") or die(mysql_error());
header("Location: settings.php?kvar");
} else
{ header("Location: settings.php?uspjeh"); }
}
else if ($_POST['Submit']=='Update')
{
$result = mysql_query("SELECT user_email,country FROM users WHERE user_name='$_SESSION[user]'") or die(mysql_error());
list ($user_email, $user_country) = mysql_fetch_row($result);
if ($user_name == $_SESSION['user'])
{
$newemail = ($_POST['newemail']);
$newcountry = ($_POST['newcountry']);
mysql_query("Update users
SET user_email = '$newemail' AND country = '$newcountry'
WHERE user_name = '$_SESSION[user]'
") or die(mysql_error());
// header("Location: settings.php?kvar");
}
else { header("Location: settings.php?uspjeh"); }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="hr-HR" xmlns="http://www.w3.org/1999/xhtml" lang="hr-HR">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-language" content="hr-HR">
</head>
<body>
<p>
<?php if (isset($_GET['kvar'])) { echo '<div class="msg" style="color: green;">Info Updated</div>'; } ?>
<?php if (isset($_GET['uspjeh'])) { echo '<div class="msg" style="color: red;">Error</div>'; } ?>
</p>
<h2>Change Password</h2>
<fieldset>
<form action="settings.php" method="post" name="form3" id="form3">
<p>Old Password
<input name="oldpwd" type="password" id="oldpwd">
</p>
<p>New Password:
<input name="newpwd" type="password" id="newpwd">
</p>
<p>
<input name="Submit" type="submit" id="Submit" value="Change">
</p>
</fieldset>
<br />
<fieldset>
Current e-mail:<div style="font-weight: bold;"><?php echo $_SESSION['user_email']; ?></div>
<br />
New: <input name="newemail" id="newemail">
<br />
<br />
Current location:<div style="font-weight: bold;"><?php echo $_SESSION['country']; ?></div>
<br />
New: <input name="newcountry" id="newcountry">
<br />
<input name="Submit" type="submit" id="Submit" value="Update">
</fieldset>
</form>
</body>
</html>