User Profiles - Edit Profile Not Working

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:

User Profiles - Edit Profile Not Working

Post by TehCrayz »

Me again, i'm having a problem with the edit_profile page, firstly, my location, email and about me are not in the textfields (<?php echo $user_info['email']; ?>) and also when i click update, the 'Your profile has been changed' message doesn't appear.

Here's my .php files.

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 have entered is invalid.';
	}
	
	if (preg_math('#"[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">
.round{
border-radius:25px;
-moz-border-radius:25px; /* Firefox 3.6 and earlier */
padding:10px;
background:yellow;
border: 2px dotted red;
}
</style>
<title><?php echo $_SESSION['username']; ?>'s Profile - Edit your profile</title>
</head>
<body>
<center>
<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>
<center>
<form action="" method="post">
<div>
<label for="email">Email:</label>
<br>
<input type"text" name="email" id="email" class="round" value="<?php echo $user_info['email']; ?>" />
</div>
<div>
<label for="location">Location:</label>
<br>
<input type"text" name="email" id="email" class="round" value="<?php echo $user_info['location']; ?>" />
</div>
<div>
<label for="about">About Me:</label>
<br>
<textarea name="about" id="about" rows="14" class="round" cols="50"><?php echo strip_tags($user_info['about']); ?></textarea>
</div>
<div>
<input type="submit" value="Update" />
</div>
</form>
</body>
</html>
Profile.php
<?php

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

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


?>
<?php
mysql_connect("localhost","root","*hello*");
mysql_select_db("commentbox");
$name=strip_tags(@$_POST['name']);
$comment=strip_tags(@$_POST['comment']);
$submit=@$_POST['submit'];

$dbLink = mysql_connect("localhost", "root", "jdjjjj");
	mysql_query("SET character_set_client=utf8", $dbLink);
	mysql_query("SET character_set_connection=utf8", $dbLink);

if($submit)
{
if($name&&$comment)
{
$insert=mysql_query("INSERT INTO commenttable (name,comment) VALUES ('$name','$comment') ");
}
else
{
echo "Please fill in <b>all</b> the fields.";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
div.ex
{
width:220px;
padding:10px;
border:5px solid gray;
margin:0px;
}
</style>
<title><?php echo $user_info['username']; ?>'s Profile - GameCrayz</title>
</head>
<body>
<div> 
<?php

if ($user_info === false){
echo 'That user does not exist.';
}else{
?>
<h1><?php echo $user_info['firstname']; ?> <?php echo $user_info['lastname']; ?></h1>
<p>Username: <?php echo $user_info['username']; ?></p>
<p>Gender: <?php echo ($user_info['gender'] ==1) ? 'Male' : 'Female'; ?></p>
<p>Email: <?php echo $user_info['email']; ?></p>
<p>Location: <?php echo $user_info['location']; ?></p>
<p>About me:<br><?php echo $user_info['about']; ?></p>
<a href='edit_profile.php'>Edit profile</a>
<?php
}
?>
</div>
<div class="ex">
<center>
<form action="" method="POST">
<table>
<tr><td>Name: <br><input type="text" name="name" placeholder='Enter your name...' style="width:150px;height:50px;font-family:cursive;border:double 12px #6DB72C;"/></td></tr>
<tr><td colspan="2">Comment: </td></tr>
<tr><td colspan="5"><textarea name="comment" rows="5" cols="50" style="width:200px;height:100px;font-family:cursive;border:double 12px #6DB72C;" placeholder='Enter a comment...'></textarea></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value='Comment'></td></tr>
</table>
</form>

<?php
$dbLink = mysql_connect("localhost", "root", "...");
	mysql_query("SET character_set_results=utf8", $dbLink);
	mb_language('uni');
	mb_internal_encoding('UTF-8');

$getquery=mysql_query("SELECT * FROM commenttable ORDER BY id DESC");
while($rows=mysql_fetch_assoc($getquery))
{
$id=$rows['id'];
$name=$rows['name'];
$comment=$rows['comment'];
echo $name . ':<br/>' . '</br>' . $comment . '' . '<br/>' . '<hr size="1"/>'
;}
?>

</div>
</body>
</html>
User_List.php
<?php

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

?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registered Users</title>
</head>
<body>
<div>
<?php

foreach (fetch_users() as $user){
?>
	<p>
		<a href="profile.php?uid=<?php echo $user['id']; ?>"><?php echo $user['username']; ?></a>
	</p>
<?php
}

?>
</div>
</body>
</html>
Init.inc.php
<?php

session_start();

mysql_connect('localhost', 'root', '...');
mysql_select_db('phplogin');

$path = dirname(__FILE__);

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

$_SESSION['uid'] = 1;

?>
User.inc.php
<?php
//fetches all of the users from the table
function fetch_users(){
$result = mysql_query('SELECT `ID` AS `id`, `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
`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 `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(htmlentities($location));
	
	$sql = "UPDATE `users` SET
				`user_email` = '{$email}'
				`user_about` = '{$about}'
				`user_location` = '{$location}'
			WHERE `user_id` = {$_SESSION['uid']}";
			
	mysql_query($sql);
}

?>
Last edited by TehCrayz on Mon Dec 10, 2012 8:23 pm, edited 3 times in total.
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: User Profiles - Edit Profile Not Working

Post by ExtremeGaming »

There are a couple errors that could be happening:

1. Your query in fetch_user_info is failing. This might also be a result of automatically setting $_SESSION['uid'] = 1 in init.inc.php, if there is no user with uid of 1.

2. Edit: Not needed

Sorry for lack of organization there ^^ but tab doesn't work in textareas blah. You also need to remove your mysql connection details as google indexes these pages frequently. But give that a try :)
Last edited by ExtremeGaming on Mon Dec 10, 2012 8:45 pm, edited 1 time in total.
<?php while(!$succeed = try()); ?>
User avatar
TehCrayz
Posts: 38
Joined: Mon Dec 03, 2012 7:30 pm
Location: london
Contact:

Re: User Profiles - Edit Profile Not Working

Post by TehCrayz »

Nothing happened...after i click 'update' nothing happens, it just refreshes...
http://gyazo.com/ef7de92f922091801d98af3d57264bb7
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: User Profiles - Edit Profile Not Working

Post by ExtremeGaming »

Edit_profile.php
<label for="location">Location:</label>
<br>
<input type"text" name="email" id="email" class="round" value="<?php echo $user_info['location']; ?>" />
Check the name on that textfield :)
<?php while(!$succeed = try()); ?>
User avatar
TehCrayz
Posts: 38
Joined: Mon Dec 03, 2012 7:30 pm
Location: london
Contact:

Re: User Profiles - Edit Profile Not Working

Post by TehCrayz »

oh...lol :)
User avatar
TehCrayz
Posts: 38
Joined: Mon Dec 03, 2012 7:30 pm
Location: london
Contact:

Re: User Profiles - Edit Profile Not Working

Post by TehCrayz »

wth? now im getting this error message 'Fatal error: Call to undefined function preg_math() in C:\xampp\htdocs\GameCrayz\Profiles\edit_profile.php on line 12'
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: User Profiles - Edit Profile Not Working

Post by ExtremeGaming »

I think you mean preg_match
<?php while(!$succeed = try()); ?>
User avatar
TehCrayz
Posts: 38
Joined: Mon Dec 03, 2012 7:30 pm
Location: london
Contact:

Re: User Profiles - Edit Profile Not Working

Post by TehCrayz »

Grr... even more errors T_T


Warning: implode(): Invalid arguments passed in C:\xampp\htdocs\GameCrayz\Profiles\edit_profile.php on line 59


Warning: implode(): Invalid arguments passed in C:\xampp\htdocs\GameCrayz\Profiles\edit_profile.php on line 59

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 have entered is invalid.';
	}
	
	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">
.round{
border-radius:25px;
-moz-border-radius:25px; /* Firefox 3.6 and earlier */
padding:10px;
background:yellow;
border: 2px dotted red;
}
</style>
<title><?php if ($_SESSION['username']){
	echo "".$_SESSION['username']."";
}else{
echo "Please login - GameCrayz";
} ?>'s Profile - Edit your profile</title>
</head>
<body>
<center>
<div>
<?php

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

?>
</div>
<center>
<form action="" method="post">
<div>
<label for="email">Email:</label>
<br>
<input type"text" name="email" id="email" class="round" value="<?php echo $user_info['email']; ?>" />
</div>
<div>
<label for="location">Location:</label>
<br>
<input type"text" name="location" id="location" class="round" value="<?php echo $user_info['location']; ?>" />
</div>
<div>
<label for="about">About Me:</label>
<br>
<textarea name="about" id="about" rows="14" class="round" cols="50"><?php echo strip_tags($user_info['about']); ?></textarea>
</div>
<div>
<input type="submit" value="Update" />
</div>
</form>
</body>
</html>
Profile.php
<?php

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

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


?>
<?php
mysql_connect("localhost","root","...");
mysql_select_db("commentbox");
$name=strip_tags(@$_POST['name']);
$comment=strip_tags(@$_POST['comment']);
$submit=@$_POST['submit'];

$dbLink = mysql_connect("localhost", "root", "...");
	mysql_query("SET character_set_client=utf8", $dbLink);
	mysql_query("SET character_set_connection=utf8", $dbLink);

if($submit)
{
if($name&&$comment)
{
$insert=mysql_query("INSERT INTO commenttable (name,comment) VALUES ('$name','$comment') ");
}
else
{
echo "Please fill in <b>all</b> the fields.";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
div.ex
{
width:220px;
padding:10px;
border:5px solid gray;
margin:0px;
}
</style>
<title><?php echo $user_info['username']; ?>'s Profile - GameCrayz</title>
</head>
<body>
<div> 
<?php

if ($user_info === false){
echo 'That user does not exist.';
}else{
?>
<h1><?php echo $user_info['firstname']; ?> <?php echo $user_info['lastname']; ?></h1>
<p>Username: <?php echo $user_info['username']; ?></p>
<p>Gender: <?php echo ($user_info['gender'] ==1) ? 'Male' : 'Female'; ?></p>
<p>Email: <?php echo $user_info['email']; ?></p>
<p>Location: <?php echo $user_info['location']; ?></p>
<p>About me:<br><?php echo $user_info['about']; ?></p>
<a href='edit_profile.php'>Edit profile</a>
<?php
}
?>
</div>
<div class="ex">
<center>
<form action="" method="POST">
<table>
<tr><td>Name: <br><input type="text" name="name" placeholder='Enter your name...' style="width:150px;height:50px;font-family:cursive;border:double 12px #6DB72C;"/></td></tr>
<tr><td colspan="2">Comment: </td></tr>
<tr><td colspan="5"><textarea name="comment" rows="5" cols="50" style="width:200px;height:100px;font-family:cursive;border:double 12px #6DB72C;" placeholder='Enter a comment...'></textarea></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value='Comment'></td></tr>
</table>
</form>

<?php
$dbLink = mysql_connect("localhost", "root", "....");
	mysql_query("SET character_set_results=utf8", $dbLink);
	mb_language('uni');
	mb_internal_encoding('UTF-8');

$getquery=mysql_query("SELECT * FROM commenttable ORDER BY id DESC");
while($rows=mysql_fetch_assoc($getquery))
{
$id=$rows['id'];
$name=$rows['name'];
$comment=$rows['comment'];
echo $name . ':<br/>' . '</br>' . $comment . '' . '<br/>' . '<hr size="1"/>'
;}
?>

</div>
</body>
</html>
Last edited by TehCrayz on Mon Dec 10, 2012 10:38 pm, edited 1 time in total.
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: User Profiles - Edit Profile Not Working

Post by ExtremeGaming »

On line 12 you're missing an underscore for $POST['location']

And that foreach I told you to add earlier is causing the implode error I think. I'm not too experienced with implode but removing the foreach won't hurt anything
<?php while(!$succeed = try()); ?>
User avatar
TehCrayz
Posts: 38
Joined: Mon Dec 03, 2012 7:30 pm
Location: london
Contact:

Re: User Profiles - Edit Profile Not Working

Post by TehCrayz »

The errors are now working but they're not working properly.
http://gyazo.com/16cd47364adf5c4e344b6bdb8adc6563
i used only a-z chars, yet it tells me to only use a-z chars
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: User Profiles - Edit Profile Not Working

Post by ExtremeGaming »

Change if(preg_match

to if(!preg_match
<?php while(!$succeed = try()); ?>
User avatar
TehCrayz
Posts: 38
Joined: Mon Dec 03, 2012 7:30 pm
Location: london
Contact:

Re: User Profiles - Edit Profile Not Working

Post by TehCrayz »

:) it works, but it doesn't actually change the info.
http://gyazo.com/100c98d5c2ff55fb42fc5700ebb348af
http://gyazo.com/4fd92c425135ce313cf6a1eb0a64e57f

Ugh..this is getting more and more confusing... @.@
imma go to sleep now.
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: User Profiles - Edit Profile Not Working

Post by ExtremeGaming »

You need to set $_SESSION['uid'] at login and remove it from init.inc.php
<?php while(!$succeed = try()); ?>
User avatar
TehCrayz
Posts: 38
Joined: Mon Dec 03, 2012 7:30 pm
Location: london
Contact:

Re: User Profiles - Edit Profile Not Working

Post by TehCrayz »

How would i do that?
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: User Profiles - Edit Profile Not Working

Post by ExtremeGaming »

Post the processing file of your login.
<?php while(!$succeed = try()); ?>
User avatar
TehCrayz
Posts: 38
Joined: Mon Dec 03, 2012 7:30 pm
Location: london
Contact:

Re: User Profiles - Edit Profile Not Working

Post by TehCrayz »

I havnt been on better php for a while @.@


login.php
<?php     

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

$errors = array();

if (isset($_POST['username'], $_POST['password'])){
	if (empty($_POST['username'])){
		$errors[] = 'The username cannot be empty.';
	}
	
	if (empty($_POST['password'])){
		$errors[] = 'The password cannot be empty.';
	}
	
	if (valid_credentials($_POST['username'], $_POST['password']) === false){
		$errors[] = 'Username and/or Password is incorrect.';
	}
	
	if (empty($errors)){
		$_SESSION['username'] = htmlentities($_POST['username']);
		
		header('Location: Main.php');
		die();
	}
}

?>
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
var message="Function Disabled!";
///////////////////////////////////
function clickIE() {if (document.all) {alert(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {alert(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")
// --> 
</script>
<title>Login - GameCrayz</title>
<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>
<center>
<img src='../login.png'>
<span style="color:#FFFFFF">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title></title>
</head>
<body>
<form action="" method="post">
<p>
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php if (isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" />
</p>
<p>
<label for="password">Password:</label>
<input type="password" name="password" id="password" />
</p>
<p>
<input type="submit" value="Login" />
</p>
</form>
<div>
<?php
if (empty($errors) === false){
	?>
	<ul>
		<?php
			
			foreach ($errors as $error){
				echo "<li>{$error}</li>";
			}
			
		?>
	</ul>
	<?php
}else{
echo 'Need an account? <a href="register.php">Register here</a>!';
}
?>
</div>
</body>
</html>
<html>
<body bgcolor='#000000' >
<!-- Start of Fireworks -->
<script language="JavaScript">
CL=new Array('#ff0000','#00ff00','#ffffff','#ff00ff','#ffa500','#ffff00','#00ff00','#ffffff','#ff00ff')
CL2=new Array('#ffa500','#00ff00','#FFAAFF','#fff000','#fffffF')
Xpos=130;
Ypos=130;
I='#00ff00';
C=0;
S=5;
H=null;
W=null;
Y=null;
NS4=(document.layers);
NS6=(document.getElementById&&!document.all);
IE4=(document.all);
A=14;
E=120;
L=null;
if (NS4){
for (i=0; i < A; i++)
document.write('<LAYER NAME="nsstars'+i+'" TOP=0 LEFT=0 BGCOLOR='+I+' CLIP="0,0,2,2"></LAYER>');
}
if (NS6){
window.document.body.style.overflow='hidden';
for (i=0; i < A; i++)
document.write('<div id="ns6stars'+i+'" style="position:absolute;top:0px;left:0px;height:2px;width:2px;font-size:2px;background:'+I+'"></div>');
}
if (IE4){
document.write('<div id="ie" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < A; i++)
document.write('<div id="iestars" style="position:absolute;top:0;left:0;width:2px;height:2px;background:'+I+';font-size:2px"></div>');
document.write('</div></div>');
}
function Fireworks(){
H=(NS4||NS6)?window.innerHeight:window.document.body.clientHeight;
W=(NS4||NS6)?window.innerWidth:window.document.body.clientWidth;
Y=(NS4||NS6)?window.pageYOffset:window.document.body.scrollTop;
for (i=0; i < A; i++){
if (IE4)L=iestars.style;
if (NS4)L=document.layers["nsstars"+i];
if (NS6)L=document.getElementById("ns6stars"+i).style;
var F = CL[Math.floor(Math.random()*CL.length)];
var RS=Math.round(Math.random()*2);
L.top = Ypos + E*Math.sin((C+i*5)/3)*Math.sin(C/100)
L.left= Xpos + E*Math.cos((C+i*5)/3)*Math.sin(C/100)
if (C < 110){
 if (NS4){L.bgColor=I;L.clip.width=1;L.clip.height=1}
 if (IE4||document.getElementById)
 {L.background=I;L.width=1;L.height=1;L.fontSize=1}
 }
else{
 if (NS4){L.bgColor=F;L.clip.width=RS;L.clip.height=RS}
 if (IE4||document.getElementById){L.background=F;L.width=RS;L.height=RS;L.fontSize=RS}
 }
}
if (C > 220){
 C=0;
 var NC = CL2[Math.floor(Math.random()*CL2.length)];
 I=NC;
 E=Math.round(100+Math.random()*90);
 Ypos = E+Math.round(Math.random()*(H-(E*2.2)))+Y;
 Xpos = E+Math.round(Math.random()*(W-(E*2.2)));
}
C+=S;
setTimeout("Fireworks()",10);
}
Fireworks();
// -->
</script>
<!-- End of Fireworks -->
<style type="text/css">
</style>
<script language="JavaScript1.2">

var x,y
var kern=20 
var flag=0
var message="Welcome to GameCrayz"
message=message.split("")
var xpos=new Array()
for (i=0;i<message.length;i++) {
	xpos[i]=-50
	}
var ypos=new Array()
for (i=0;i<message.length;i++) {
	ypos[i]=-50
	}
function handlerMM(e){
	x = (e) ? e.pageX : document.body.scrollLeft+event.clientX
	y = (e) ? e.pageY : document.body.scrollTop+event.clientY
	flag=1
	}
function makebanner() {
	if (flag==1) {
		for (i=message.length-1; i>=1; i--) {
			xpos[i]=xpos[i-1]+kern
			ypos[i]=ypos[i-1]
			}
		xpos[0]=x+kern
		ypos[0]=y
		for (i=0; i<message.length; i++) {
			if (document.getElementById) {
				var thisspan = document.getElementById("span"+i).style
				} else {
				var thisspan = eval((document.layers)?"document.span"+i:"span"+(i)+".style")
				}
			if (thisspan.posLeft) {
				thisspan.posLeft=xpos[i]
				thisspan.posTop=ypos[i]
				}
			if (!thisspan.posLeft) {
				thisspan.left=xpos[i]
				thisspan.top=ypos[i]
				}
			}
		}
		var timer=setTimeout("makebanner()",30)
	}
window.onload=makebanner;
</script>



<script language="JavaScript1.2">
for (i=0;i<message.length;i++) {
document.write("<span id='span"+i+"' class='spanstyle'>")
document.write(message[i])
document.write("</span>")
}
if (document.layers){
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;

</script>

<style type="text/css">
<!--
.spanstyle {
position:absolute;
visibility:visible;
top:-50px;
font-size:10pt;
font-family:Verdana;
font-weight:italic;
color:808066;
}
BODY {
width:100%;overflow-x:hidden;overflow-y:scroll;
}
-->
</style>
<script language="JavaScript1.2">

var x,y
var kern=20 
var flag=0
var message="Welcome to GameCrayz, Please login."
message=message.split("")
var xpos=new Array()
for (i=0;i<message.length;i++) {
	xpos[i]=-50
	}
var ypos=new Array()
for (i=0;i<message.length;i++) {
	ypos[i]=-50
	}
function handlerMM(e){
	x = (e) ? e.pageX : document.body.scrollLeft+event.clientX
	y = (e) ? e.pageY : document.body.scrollTop+event.clientY
	flag=1
	}
function makebanner() {
	if (flag==1) {
		for (i=message.length-1; i>=1; i--) {
			xpos[i]=xpos[i-1]+kern
			ypos[i]=ypos[i-1]
			}
		xpos[0]=x+kern
		ypos[0]=y
		for (i=0; i<message.length; i++) {
			if (document.getElementById) {
				var thisspan = document.getElementById("span"+i).style
				} else {
				var thisspan = eval((document.layers)?"document.span"+i:"span"+(i)+".style")
				}
			if (thisspan.posLeft) {
				thisspan.posLeft=xpos[i]
				thisspan.posTop=ypos[i]
				}
			if (!thisspan.posLeft) {
				thisspan.left=xpos[i]
				thisspan.top=ypos[i]
				}
			}
		}
		var timer=setTimeout("makebanner()",12)
	}
window.onload=makebanner;
</script>



<script language="JavaScript1.2">
for (i=0;i<message.length;i++) {
document.write("<span id='span"+i+"' class='spanstyle'>")
document.write(message[i])
document.write("</span>")
}
if (document.layers){
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;

</script>
</body>
</html>
]


init.inc.php
<?php

session_start();

mysql_connect('localhost', 'root', '*MEOW*');
mysql_select_db('phplogin');

$path = dirname(__FILE__);

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

$_SESSION['uid'] = 1;

?>


user.inc.php
<?php
//fetches all of the users from the table
function fetch_users(){
$result = mysql_query('SELECT `ID` AS `id`, `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
`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 `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(htmlentities($location));
	
	$sql = "UPDATE `users` SET
				`user_email` = '{$email}',
				`user_about` = '{$about}',
				`user_location` = '{$location}'
			WHERE `user_id` = {$_SESSION['uid']}";
			
	mysql_query($sql);
}

?>
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: User Profiles - Edit Profile Not Working

Post by ExtremeGaming »

Where is this "valid_credentials" function it shows?

You will need to query your database at some point to set their session uid from the database. It should look something like this:
// DO NOT forget to filter the variables with mysql_real_escape_string();
$result = mysql_query("SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'");

while(($row = mysql_fetch_array($result)) !== false) {

$_SESSION['username'] = $row['username'];
$_SESSION['uid'] = $row['uid'];

}
<?php while(!$succeed = try()); ?>
User avatar
TehCrayz
Posts: 38
Joined: Mon Dec 03, 2012 7:30 pm
Location: london
Contact:

Re: User Profiles - Edit Profile Not Working

Post by TehCrayz »

When i go to reigstered users page, i keep getting

Notice: Undefined variable: username in C:\xampp\htdocs\GameCrayz\Profiles\core\inc\user.inc.php on line 4

Notice: Undefined variable: password in C:\xampp\htdocs\GameCrayz\Profiles\core\inc\user.inc.php on line 4

User.inc.php
<?php
//fetches all of the users from the table
function fetch_users(){
$result = mysql_query("SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'");

$users = array();

while (($row = mysql_fetch_assoc($result)) !== false){

$_SESSION['username'] = $row['username'];
$_SESSION['uid'] = $row['uid'];
}

return $users;
}
//fetches profile info for the given user
function fetch_user_info($uid){
$uid = (int)$uid;

$sql = "SELECT
`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 `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(htmlentities($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', 'jdiwfjiwejfoiwej[ownrghquriven[i');
mysql_select_db('phplogin');

$path = dirname(__FILE__);

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

$_SESSION['uid'] = 1;

?>
User_list.php
<?php

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

?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registered Users</title>
</head>
<body>
<div>
<?php

foreach (fetch_users() as $user){
?>
<p>
<a href="profile.php?uid=<?php echo $user['id']; ?>"><?php echo $user['username']; ?></a>
</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 have entered is invalid.';
	}
	
	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">
.round{
border-radius:25px;
-moz-border-radius:25px; /* Firefox 3.6 and earlier */
padding:10px;
background:yellow;
border: 2px dotted red;
}
</style>
<title><?php if ($_SESSION['username']){
	echo "".$_SESSION['username']."";
}else{
echo "Please login - GameCrayz";
} ?>'s Profile - Edit your profile</title>
</head>
<body>
<center>
<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>
<center>
<form action="" method="post">
<div>
<label for="email">Email:</label>
<br>
<input type"text" name="email" id="email" class="round" value="<?php echo $user_info['email']; ?>" />
</div>
<div>
<label for="location">Location:</label>
<br>
<input type"text" name="location" id="location" class="round" value="<?php echo $user_info['location']; ?>" />
</div>
<div>
<label for="about">About Me:</label>
<br>
<textarea name="about" id="about" rows="14" class="round" cols="50"><?php echo strip_tags($user_info['about']); ?></textarea>
</div>
<div>
<input type="submit" value="Update" />
</div>
</form>
</body>
</html>
Profile.php
    <?php
     
    include('core/init.inc.php');
     
    $user_info = fetch_user_info($_GET['uid']);
     
     
    ?>
    <?php
    mysql_connect("localhost","root","dsdasdasd");
    mysql_select_db("commentbox");
    $name=strip_tags(@$_POST['name']);
    $comment=strip_tags(@$_POST['comment']);
    $submit=@$_POST['submit'];
     
    $dbLink = mysql_connect("localhost", "root", "sdasdasd");
            mysql_query("SET character_set_client=utf8", $dbLink);
            mysql_query("SET character_set_connection=utf8", $dbLink);
     
    if($submit)
    {
    if($name&&$comment)
    {
    $insert=mysql_query("INSERT INTO commenttable (name,comment) VALUES ('$name','$comment') ");
    }
    else
    {
    echo "Please fill in <b>all</b> the fields.";
    }
    }
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
    div.ex
    {
    width:220px;
    padding:10px;
    border:5px solid gray;
    margin:0px;
    }
    </style>
    <title><?php echo $user_info['username']; ?>'s Profile - GameCrayz</title>
    </head>
    <body>
    <div>
    <?php
     
    if ($user_info === false){
    echo 'That user does not exist.';
    }else{
    ?>
    <h1><?php echo $user_info['firstname']; ?> <?php echo $user_info['lastname']; ?></h1>
    <p>Username: <?php echo $user_info['username']; ?></p>
    <p>Gender: <?php echo ($user_info['gender'] ==1) ? 'Male' : 'Female'; ?></p>
    <p>Email: <?php echo $user_info['email']; ?></p>
    <p>Location: <?php echo $user_info['location']; ?></p>
    <p>About me:<br><?php echo $user_info['about']; ?></p>
    <a href='edit_profile.php'>Edit profile</a>
    <?php
    }
    ?>
    </div>
    <div class="ex">
    <center>
    <form action="" method="POST">
    <table>
    <tr><td>Name: <br><input type="text" name="name" placeholder='Enter your name...' style="width:150px;height:50px;font-family:cursive;border:double 12px #6DB72C;"/></td></tr>
    <tr><td colspan="2">Comment: </td></tr>
    <tr><td colspan="5"><textarea name="comment" rows="5" cols="50" style="width:200px;height:100px;font-family:cursive;border:double 12px #6DB72C;" placeholder='Enter a comment...'></textarea></td></tr>
    <tr><td colspan="2"><input type="submit" name="submit" value='Comment'></td></tr>
    </table>
    </form>
     
    <?php
    $dbLink = mysql_connect("localhost", "root", "dsdasdas");
            mysql_query("SET character_set_results=utf8", $dbLink);
            mb_language('uni');
            mb_internal_encoding('UTF-8');
     
    $getquery=mysql_query("SELECT * FROM commenttable ORDER BY id DESC");
    while($rows=mysql_fetch_assoc($getquery))
    {
    $id=$rows['id'];
    $name=$rows['name'];
    $comment=$rows['comment'];
    echo $name . ':<br/>' . '</br>' . $comment . '' . '<br/>' . '<hr size="1"/>'
    ;}
    ?>
     
    </div>
    </body>
    </html>
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: User Profiles - Edit Profile Not Working

Post by ExtremeGaming »

I'm not sure why you are editing the function fetch_users(). Or even setting sessions within it, where it should be used for displaying users

You are supposed to set the sessions within the function that you are using to login the users
if (empty($errors)){
                $_SESSION['username'] = htmlentities($_POST['username']);
               
                header('Location: Main.php');
                die();
        }
Remove the setting of the $_SESSION['username'] and the redirect and create a function that does all of that. (purely for organization) Something like this:
function login_user($username,$password) {

	// make sure you connect to the database

        $username = mysql_real_escape_string($username);
        $password = mysql_real_escape_string($password);

	$result = mysql_query("SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'");

	if(mysql_num_rows($result) != "0") {

		while (($row = mysql_fetch_array($result) !== false)
		{
			$_SESSION['uid'] =		$row['uid'];
			$_SESSION['username'] = 	$row['username'];
		}
		
		header("Location: Main.php");
		die;

	}

}
<?php while(!$succeed = try()); ?>
Post Reply