Hey guys i'm getting an error using this code to update user details in a database
an error is
"Notice: Undefined index: sex in E:\programming\EasyPHP-5.3.6.1\www\ch@\profile.php on line 103
Notice: Undefined index: country in E:\programming\EasyPHP-5.3.6.1\www\ch@\profile.php on line 104
Notice: Undefined index: city in E:\programming\EasyPHP-5.3.6.1\www\ch@\profile.php on line 105
Notice: Undefined index: relationship in E:\programming\EasyPHP-5.3.6.1\www\ch@\profile.php on line 106"
PHP Code:
<?php
require 'inc/head.inc';
if(!isset($_SESSION['id']))
header('Location:index.php');
else
{
require 'inc/header.inc';
print 'Update profile or leave blank if you don\'t want to update';
$sql = "SELECT * FROM users WHERE id = '{$_SESSION['id']}'";
$query = @mysql_query($sql, $con);
$result = @mysql_fetch_array($query);
if(isset($_SESSION['errors']))
if(is_array($_SESSION['errors']))
foreach($_SESSION['errors'] as $error)
print $error;
if(!isset($_POST['count']))
{
print '<form action="" method=post>
<div class=dl>First Name</div>
<input type=text name=fname size=10 maxlength=30>
<div class=dl>Nick</div>
<input type=text name=nick size=10 maxlength=20>
<div class=dl>Last Name</div>
<input type=text name=sname size=10 maxlength=30>
<input type=hidden name=count>
<div class=dl>Gender</div>
<select name=sex>
<option value=m>Male</option>
<option value=f>Female</option>
</select><br>
<div class=dl>Country</div>
<input type=text name=country size=10 maxlength=30>
<div class=dl>City</div>
<input type=text name=city size=10 maxlength=30>
<div class=dl>Relationship</div>
<select name=relationship>
<option value="single">Single</option>
<option value="in a relationship">In a relationship</option>
<option value="engaged">Engaged</option>
<option value="married">Married</option>
<option value="available">Available</option>
</select><br>
<input class=button type=submit value=Update>
</form>';
}
else
{
$_SESSION['fname'] = @mysql_real_escape_string(htmlentities(stripslashes($_POST['fname'])));
$_SESSION['sname'] = @mysql_real_escape_string(htmlentities(stripslashes($_POST['sname'])));
$_SESSION['nick'] = @mysql_real_escape_string(htmlentities(stripslashes($_POST['nick'])));
$_SESSSION['sex'] = @mysql_real_escape_string(htmlentities(stripslashes($_POST['sex'])));
$_SESSSION['country'] = @mysql_real_escape_string(htmlentities(stripslashes($_POST['country'])));
$_SESSSION['city'] = @mysql_real_escape_string(htmlentities(stripslashes($_POST['city'])));
$_SESSSION['relationship'] = @mysql_real_escape_string(htmlentities(stripslashes($_POST['relationship'])));
$error = array();
if(strlen($_SESSION['year']) != 4)
$error = '<br>Year must be a 4 digit';
if(strlen($_SESSION['month']) != 2 || $_SESSION['month'] < 1 || $_SESSION['month'] > 12)
$error = '<br>Enter a valid month';
if(strlen($_SESSION['day']) != 2 || $_SESSION['day'] < 1 || $_SESSION['day'] > 31)
$error = '<br>You entered an invalid day';
if(count($error))
{
$_SESSION['error'] = $error;
if(is_array($_SESSION['error']))
{
foreach($_SESSION['error'] as $errors)
print $errors;
}
else
print $_SESSION['error'];
unset($_SESSION['error']);
unset($_POST['count']);
}
else
{
#Seems like my problem is below this comment
$update = "UPDATE users SET `fname` = '{$_SESSION['fname']}',
`sname` = '{$_SESSION['sname']}',
`nick` = '{$_SESSION['nick']}',
`birthday` = '{$_SESSION['bday']}',
`sex` = '{$_SESSION['sex']}',
`country` = '{$_SESSION['country']}',
`city` = '{$_SESSION['city']}',
`relationship` = '{$_SESSION['relationship']}'
WHERE `id` = '{$_SESSION['id']}'";
if(!$query = @mysql_query($update))
print 'There was an error updating your details';
else
print 'Your details were updated <a href=home.php>continue</a>';
}
}
require 'inc/foot.inc';
}
?>
"Notice: Undefined index: sex in E:\programming\EasyPHP-5.3.6.1\www\ch@\profile.php on line 103
Notice: Undefined index: country in E:\programming\EasyPHP-5.3.6.1\www\ch@\profile.php on line 104
Notice: Undefined index: city in E:\programming\EasyPHP-5.3.6.1\www\ch@\profile.php on line 105
Notice: Undefined index: relationship in E:\programming\EasyPHP-5.3.6.1\www\ch@\profile.php on line 106"
Comment