profile script

This is a discussion on "profile script" within the PHP Forum section. This forum, and the thread "profile script are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old May 12th, 2007, 02:17
Up'n'Coming Member
Join Date: Jul 2006
Location: manila
Age: 28
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
profile script

helo,

can anyone have sample script on how to edit, update a profile.php of a user

thanks
Reply With Quote

  #2 (permalink)  
Old May 12th, 2007, 15:24
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: profile script

you know how to use forms to write information to a database right?

Well insteaed of usint INSERT... use UPDATE .... you can also call the info from the database into the forms "selected" or "value" tags.. to make the form display the current information for editing.

I know making a profile sounds complicated.... but it really isnt anythign special .... dont let it scare you ... just think about the logic.

Try and write something yourself, and then come back when it doesnt work and ill point you in the right direction.
Reply With Quote
  #3 (permalink)  
Old May 12th, 2007, 17:28
Up'n'Coming Member
Join Date: Jul 2006
Location: manila
Age: 28
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: profile script

hello,

i have this script below but I'm not sure if this is correct, kindly check

thanks..

Code: Select all
<?php
ob_start();

require("../../include/z_db.php");

if($_POST['Uname'] == '')
{
header('location:login.php');
exit
}

//get the users profile
$result = mysql_query("SELECT * FROM staff_users WHERE Uname='{$_SESSION['Uname']}'") or die(mysql_error());

$row = mysql_fetch_array( $result );

if($_GET['action'] == 'update')
{
if($_POST['Email'] == '')
   {
      echo error("blank");
      exit;
   }
   else
   {

      //update
      $_Email = str_replace("<", "", $_POST['Email']);
     
      $result = mysql_query("UPDATE staff_users SET Email='" . $_Email . "' WHERE Uname='{$_SESSION['Uname']}'")
      or die(mysql_error());
   }
}
function error($error)
{
if($error == 'blank')
{
echo "<b>Please fill in all the fields</b>";
}
if($error == 'updated')
{
echo "<b>Updated successfully</b>";
}
}
?>

<form method=post action=profile.php?action=update>
<table>
<tr><td>Username:</td><td><b>" . $row['Uname'] . "</b></td></tr>
<tr><td>Email:</td><td><input type=text name=Email value=" . $row['Email'] . "></td></tr>
<tr><td><a href=changepass.php>Change password</a></td><td></td></tr>
<tr><td></td><td><input type=submit value=Update></td></tr>
</table></form>
Reply With Quote
  #4 (permalink)  
Old May 12th, 2007, 18:44
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: profile script

dont us "_" for your own variables .. eg ; $_Email should just be $email ... dont think it actually has any negative effects ... but its a bad habbit.

Apart from that it looks ok... easy enough to follow .... you might be better off usine $_SESSION[''] as opposed to $_POST to track a logged in user however.

Have you tried to use it yet ?

edit:

Instead of this:
Code: Select all
if($_POST['Uname'] == '')
use :
Code: Select all
if($_SESSION['Uname'] != "yes")
just remember to set $_SESSION['Uname] == "yes" .. when they first log in

Last edited by Accurax; May 12th, 2007 at 18:46.
Reply With Quote
  #5 (permalink)  
Old May 14th, 2007, 04:25
Up'n'Coming Member
Join Date: Jul 2006
Location: manila
Age: 28
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: profile script

hello accurax thanks for the reply, i edit now the script and when i run it, there is an error occur

error:
Parse error: parse error, unexpected T_IF in F:\server\htdocs\coupon\cpanel\acct\profile.php on line 49

Code: Select all
<?php
ob_start();
require ("../../include/z_db.php");
$_SESSION['Uname'] == "yes"
//check if the session Uname is in use
if($_SESSION['Uname'] == "yes")
{
header("Location: login.php");
exit;
}
//get the users profile
$result = mysql_query("SELECT * FROM staff_users WHERE Uname='{$_SESSION['Uname']}'") or die(mysql_error());
$row = mysql_fetch_array( $result );
?>

<form method=post action=profile.php?action=update>
<table>
<tr><td>Username:</td><td><b><? $row['Uname']?></b></td></tr>
<tr><td>Email:</td><td><input type=text name=Email value="<? $row['Email'] ?>"></td></tr>
<tr><td><a href=changepassword.php>Change password</a></td><td></td></tr>
<tr><td></td><td><input type=submit value=Update></td></tr>
</table>
</form>

<?php

if($_GET['action'] == 'update')
{
if( $_POST['Email'] == '')
   {
      echo error("blank");
      exit;
   }
   else
   {

      //update
      $_Email = str_replace("<", "", $_POST['Email']);
    
      $result = mysql_query("UPDATE staff_users SET Email='" . $_Email . "' WHERE Uname='{$_SESSION['Uname']}'")
      or die(mysql_error());
   }
}
function error($error)
{
if($error == 'blank')
{
echo "<b>Please fill in all the fields</b>";
}
if($error == 'updated')
{
echo "<b>Updated successfully</b>";
}
}
?>
Reply With Quote
Reply

Tags
profile

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Profile page unitedcraig Webforumz Cafe 2 Feb 11th, 2008 16:27
edit a profile.php csun PHP Forum 3 Mar 17th, 2007 23:50
user profile help Aaron1988 Flash & Multimedia Forum 12 Aug 31st, 2006 14:04
Php User Profile Help Aaron1988 PHP Forum 1 Aug 16th, 2006 00:54


All times are GMT. The time now is 11:32.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43