Error in Edit_Profile

Post here is you are having problems with any of the tutorials.
Post Reply
User avatar
TehCrayz
Posts: 38
Joined: Mon Dec 03, 2012 7:30 pm
Location: london
Contact:

Error in Edit_Profile

Post by TehCrayz »

Ok, after going through the whole tutorial again( http://betterphp.co.uk/board/viewtopic.php?f=7&t=2068 ), i came to a stop by a error which i have received before.

On edit_profile, when i click update i get this error.

Your location must only contain a-z, 0-9 and spaces.
http://gyazo.com/88fdafd0b27fac6bf76f0a041079c05f


User.inc.php
<?php
// Fetches all of the users from the table
function fetch_users(){
	$result = mysql_query('SELECT `user_id` AS `id`, `user_username` AS `username` FROM `users`');
	
	$users = array();
	
	while(($row = mysql_fetch_assoc($result)) !== false){
		$users[] = $row;
	
	}
	
	return $users;

}

// Fetches profile info for the given user.
function fetch_user_info($uid){
	$uid = (int)$uid;

	$sql = "SELECT 
				`user_username` AS `username`,
				`user_firstname` AS `firstname`,
				`user_lastname` AS `lastname`,
				`user_email` AS `email`,
				`user_about` AS `about`,
				`user_location` AS `location`,
				`user_gender` AS `gender` 
			FROM `users`
			WHERE `user_id` = {$uid}";
			
	$result = mysql_query($sql);
	
	return mysql_fetch_assoc($result);
}

//Updates the current users profile info
function set_profile_info($email, $about, $location){
	$email		= mysql_real_escape_string(htmlentities($email));
	$about		= mysql_real_escape_string(nl2br(htmlentities($about)));
	$location		= mysql_real_escape_string($location);

	$sql = "UPDATE `users` SET	
				`user_email` = '{$email}',
				`user_about` = '{$about}',
				`user_location` = '{$location}'
			WHERE `user_id` = {$_SESSION['uid']}";
			
	mysql_query($sql);
				
				
}

?>
init.inc.php
<?php
session_start();

mysql_connect('localhost', 'root', ' '');
mysql_select_db('user_profile');

$path = dirname(__FILE__);

include("{$path}/inc/user.inc.php");

$_SESSION['uid'] = 1;

?>
Profile.php
<?php

include('core/init.inc.php');

$user_info = fetch_user_info($_GET['uid']);


?>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title><?php echo $user_info['username']; ?>'s Profile - Quodec</title>
	</head>
	<body>
		<center>
			<div>
			<?php
			
			if ($user_info === false){
			
				echo 'That user does not exist.';
			}else{
			
			?>
			<h1><?php echo $user_info['username']; ?></h1>
			<p><?php echo $user_info['firstname']; ?> <?php echo $user_info['lastname']; ?>
			<p>Email: <?php echo $user_info['email']; ?></p>
			<p>Gender: <?php echo ($user_info['gender'] ==1) ? 'Male' : 'Female';  ?></p>
			<p>Location: <?php echo $user_info['location']; ?></p>
			<p><?php echo $user_info['about']; ?></p>
			<?php
			}
			?>
		</div>
	</body>
</html>
Edit profile.php
<?php

include('core/init.inc.php');

if (isset($_POST['email'], $_POST['location'], $_POST['about'])){
	$errors = array();
	
	if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false){
		$errors[] = 'The email address you entered is not valid.';
	}
	if (preg_match('#^[a-z0-9 ]+S#i', $_POST['location']) ===0){
		$errors[] = 'Your location must only contain a-z, 0-9 and spaces.';
	}
	if (empty($errors)){
		set_profile_info($_POST['email'], $_POST['about'], $_POST['location']);
	}
	
	$user_info = array(
		'email'		=> htmlentities($_POST['email']),
		'about'		=> htmlentities($_POST['about']),
		'location'	=> htmlentities($_POST['location']),
	);
}else{
	$user_info = fetch_user_info($_SESSION['uid']);
}

?>
<html>
<head>
<style type="text/css">
form {
    display: inline;
}
textarea
{
   resize: none;
}
.round{
border:0px solid;
border-radius:25px;
-moz-border-radius:25px; /* Firefox 3.6 and earlier */
padding:10px;
}
.fsSubmitButton
{
padding: 10px 15px 9px !important;
font-size: 19px !important;
background-color: #01DFD7;
text-shadow: 1px 1px #000000;
color: #ffffff;
border-radius: 50px;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
border: 1px solid #000000;
cursor: pointer;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
-moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
}
</style>
<title>Edit Profile - Quodec</title>

<script type="text/javascript">
(function()
{	
  if (window.addEventListener)
  {
    window.addEventListener("load", hide_loading_screen, false);    
  }
  else
  {
    window.attachEvent("onload", hide_loading_screen);
  }
})();

function display_loading_screen()
{
  document.getElementById("loading_screen").style.display = 'block';
}

function hide_loading_screen()
{
  document.getElementById("loading_screen").style.display = 'none';
}
</script>
<SCRIPT language=JavaScript>

fCol='444444'; //face colour.
sCol='FF0000'; //seconds colour.
mCol='444444'; //minutes colour.
hCol='444444'; //hours colour.

Ybase=30; //Clock height.
Xbase=30; //Clock width.


H='...';
H=H.split('');
M='....';
M=M.split('');
S='.....';
S=S.split('');
NS4=(document.layers);
NS6=(document.getElementById&&!document.all);
IE4=(document.all);
Ypos=0;
Xpos=0;
dots=12;
Split=360/dots;
if (NS6){
for (i=1; i < dots+1; i++){
document.write('<div id="n6Digits'+i+'" style="position:absolute;top:0px;left:0px;width:30px;height:30px;font-family:Arial;font-size:10px;color:#'+fCol+';text-align:center;padding-top:10px">'+i+'</div>');
}
for (i=0; i < M.length; i++){
document.write('<div id="Ny'+i+'" style="position:absolute;top:0px;left:0px;width:2px;height:2px;font-size:2px;background:#'+mCol+'"></div>');
}
for (i=0; i < H.length; i++){
document.write('<div id="Nz'+i+'" style="position:absolute;top:0px;left:0px;width:2px;height:2px;font-size:2px;background:#'+hCol+'"></div>');
}
for (i=0; i < S.length; i++){
document.write('<div id="Nx'+i+'" style="position:absolute;top:0px;left:0px;width:2px;height:2px;font-size:2px;background:#'+sCol+'"></div>');
}
}
if (NS4){
dgts='1 2 3 4 5 6 7 8 9 10 11 12';
dgts=dgts.split(' ')
for (i=0; i < dots; i++){
document.write('<layer name=nsDigits'+i+' top=0 left=0 height=30 width=30><center><font face=Arial size=1 color='+fCol+'>'+dgts+'</font></center></layer>');
}
for (i=0; i < M.length; i++){
document.write('<layer name=ny'+i+' top=0 left=0 bgcolor='+mCol+' clip="0,0,2,2"></layer>');
}
for (i=0; i < H.length; i++){
document.write('<layer name=nz'+i+' top=0 left=0 bgcolor='+hCol+' clip="0,0,2,2"></layer>');
}
for (i=0; i < S.length; i++){
document.write('<layer name=nx'+i+' top=0 left=0 bgcolor='+sCol+' clip="0,0,2,2"></layer>');
}
}
if (IE4){
document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=1; i < dots+1; i++){
document.write('<div id="ieDigits" style="position:absolute;top:0px;left:0px;width:30px;height:30px;font-family:Arial;font-size:10px;color:'+fCol+';text-align:center;padding-top:10px">'+i+'</div>');
}
document.write('</div></div>')
document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < M.length; i++){
document.write('<div id=y style="position:absolute;width:2px;height:2px;font-size:2px;background:'+mCol+'"></div>');
}
document.write('</div></div>')
document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < H.length; i++){
document.write('<div id=z style="position:absolute;width:2px;height:2px;font-size:2px;background:'+hCol+'"></div>');
}
document.write('</div></div>')
document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < S.length; i++){
document.write('<div id=x style="position:absolute;width:2px;height:2px;font-size:2px;background:'+sCol+'"></div>');
}
document.write('</div></div>')
}



function clock(){
time = new Date ();
secs = time.getSeconds();
sec = -1.57 + Math.PI * secs/30;
mins = time.getMinutes();
min = -1.57 + Math.PI * mins/30;
hr = time.getHours();
hrs = -1.57 + Math.PI * hr/6 + Math.PI*parseInt(time.getMinutes())/360;

if (NS6){
Ypos=window.pageYOffset+window.innerHeight-Ybase-25;
Xpos=window.pageXOffset+window.innerWidth-Xbase-30;
for (i=1; i < dots+1; i++){
 document.getElementById("n6Digits"+i).style.top=Ypos-15+Ybase*Math.sin(-1.56 +i *Split*Math.PI/180)
 document.getElementById("n6Digits"+i).style.left=Xpos-15+Xbase*Math.cos(-1.56 +i*Split*Math.PI/180)
 }
for (i=0; i < S.length; i++){
 document.getElementById("Nx"+i).style.top=Ypos+i*Ybase/4.1*Math.sin(sec);
 document.getElementById("Nx"+i).style.left=Xpos+i*Xbase/4.1*Math.cos(sec);
 }
for (i=0; i < M.length; i++){
 document.getElementById("Ny"+i).style.top=Ypos+i*Ybase/4.1*Math.sin(min);
 document.getElementById("Ny"+i).style.left=Xpos+i*Xbase/4.1*Math.cos(min);
 }
for (i=0; i < H.length; i++){
 document.getElementById("Nz"+i).style.top=Ypos+i*Ybase/4.1*Math.sin(hrs);
 document.getElementById("Nz"+i).style.left=Xpos+i*Xbase/4.1*Math.cos(hrs);
 }
}
if (NS4){
Ypos=window.pageYOffset+window.innerHeight-Ybase-20;
Xpos=window.pageXOffset+window.innerWidth-Xbase-30;
for (i=0; i < dots; ++i){
 document.layers["nsDigits"+i].top=Ypos-5+Ybase*Math.sin(-1.045 +i*Split*Math.PI/180)
 document.layers["nsDigits"+i].left=Xpos-15+Xbase*Math.cos(-1.045 +i*Split*Math.PI/180)
 }
for (i=0; i < S.length; i++){
 document.layers["nx"+i].top=Ypos+i*Ybase/4.1*Math.sin(sec);
 document.layers["nx"+i].left=Xpos+i*Xbase/4.1*Math.cos(sec);
 }
for (i=0; i < M.length; i++){
 document.layers["ny"+i].top=Ypos+i*Ybase/4.1*Math.sin(min);
 document.layers["ny"+i].left=Xpos+i*Xbase/4.1*Math.cos(min);
 }
for (i=0; i < H.length; i++){
 document.layers["nz"+i].top=Ypos+i*Ybase/4.1*Math.sin(hrs);
 document.layers["nz"+i].left=Xpos+i*Xbase/4.1*Math.cos(hrs);
 }
}

if (IE4){
Ypos=document.body.scrollTop+window.document.body.clientHeight-Ybase-20;
Xpos=document.body.scrollLeft+window.document.body.clientWidth-Xbase-20;
for (i=0; i < dots; ++i){
 ieDigits.style.pixelTop=Ypos-15+Ybase*Math.sin(-1.045 +i *Split*Math.PI/180)
 ieDigits.style.pixelLeft=Xpos-15+Xbase*Math.cos(-1.045 +i *Split*Math.PI/180)
 }
for (i=0; i < S.length; i++){
 x.style.pixelTop =Ypos+i*Ybase/4.1*Math.sin(sec);
 x.style.pixelLeft=Xpos+i*Xbase/4.1*Math.cos(sec);
 }
for (i=0; i < M.length; i++){
 y.style.pixelTop =Ypos+i*Ybase/4.1*Math.sin(min);
 y.style.pixelLeft=Xpos+i*Xbase/4.1*Math.cos(min);
 }
for (i=0; i < H.length; i++){
 z.style.pixelTop =Ypos+i*Ybase/4.1*Math.sin(hrs);
 z.style.pixelLeft=Xpos+i*Xbase/4.1*Math.cos(hrs);
 }
}
setTimeout('clock()',100);
}
clock();
//-->
</SCRIPT>
<SCRIPT language=JavaScript>

fCol='444444'; //face colour.
sCol='FF0000'; //seconds colour.
mCol='444444'; //minutes colour.
hCol='444444'; //hours colour.

Ybase=30; //Clock height.
Xbase=30; //Clock width.
</SCRIPT>
</head>
<body>
<center>
<br>
<font face="verdana">
<div>
<?php

if (isset($errors) === false){
	echo '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="" method="post">
<div>
<br />
Email:
<br>
<input type="text" class="round" name="email" id="email" placeholder="Enter a email adress here" value="<?php echo $user_info['email']; ?>" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"
onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"/>
</div>
<br />
<div>
Location:
<br>
<input type="text" class="round" name="location" id="location" value="<?php echo $user_info['location']; ?>" placeholder="Enter your location here" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"
onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"/>
</div>
<br />
<div>
About Me:
<br />
<textarea class="round" name="about" id="about" rows="12" placeholder="Add a short description about yourself" cols="50" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"
onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"><?php echo strip_tags($user_info['about']); ?></textarea>
</div>
<div>
<input type="submit" style="cursor:crosshair" class="fsSubmitButton" value="Update" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"
onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"/>
</div>
</form><form action='../Login/login.php' method='post'><input type='submit' class='fsSubmitButton' value='Back' style='cursor:crosshair' onmouseover='this.style.opacity=1;this.filters.alpha.opacity=100'  onmouseout='this.style.opacity=0.4;this.filters.alpha.opacity=40' /></form>
</body>
</html>




Should this be in a new post?
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Error in Edit_Profile

Post by Temor »

I split it into a new topic..
        if (preg_match('#^[a-z0-9 ]+S#i', $_POST['location']) ===0){
                $errors[] = 'Your location must only contain a-z, 0-9 and spaces.';
        }
remove one of the equal signs and see what happens.
User avatar
TehCrayz
Posts: 38
Joined: Mon Dec 03, 2012 7:30 pm
Location: london
Contact:

Re: Error in Edit_Profile

Post by TehCrayz »

:D When i changed my Country to USA, it worked. But then when i changed it back to UK, i still get the error
Post Reply