Jump to content

I want to make a single page that users...


forumnz

Recommended Posts

  • Replies 51
  • Created
  • Last Reply
Ok, sure...

Well its a site that the user can (doesnt need to) login to to see the members area...

When they register they input a username, password, name, age, email, phone, ect.

I want to be able to have a page that they can access when logged in that allows them to change these credentials,
(mainly password and email.)
So if you've got the primary key indexed, and you know the user is logged in you'll just a have a link for "edit information". When a user clicks that you go out and query your database based on that primary key. You prefill your html form with the data you want to allow them to update and when they click the button you just do an sql update command based on that same primary key....

That's the general process... do you have a specific problem?
So you have an html form that lets them change email and password thats all for now.

$query = "SELECT `email` FROM `usertable` WHERE `id` = $primary_key";
$result = mysql_query($query);

$row = mysql_fetch_row($result);

$go_flag = false;
if( $row )
{
  $go_flag = true; 
}

if( $go_flag )
{
  echo "<input type='text' id='email' name='email' value='" . $row[0] . "' />\n";
}
else
{
  echo "<input type='text' id='email' name='email' value='' />\n";
}


Filling in the stuff in the appropriate places and making it specific to your problem... but that's how you prefil a form and only select what you want. Likewise when you do the update command you only update the stuff you want to update.

$query = "UPDATE `usertable` SET `email` = $email WHERE `id` = $primarykey";
Well that's up to you. I don't know if you like to split up your code so that you have a page that contains primarily only your html and then post the data to a script or if you post it all to the same page.

The first thing I would do is create the html page without prefilling the values and put in whatever security checks you do to verify that the user is in fact logged in before granting access to the page. Once all that passes echo out the userid (primary key). If you can get that far we can easily help you work out the details on the query to select only the values you want editable via your form, help actually prefill the form and finally the update.

Try and get something put together and we can take it from there.
Ok heres my basic version

[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<p>Edit Profile</p>
<form id="form1" name="form1" method="post" action="edit.php">
<p>Password :
  <input name="password" type="text" id="password" />
  <br />
  Confirm Password :
  <input name="password" type="text" id="password" />
</p>
<p>Email Address :
  <input name="email" type="text" id="email" />
</p>
<p>
  <label>
  <input type="submit" name="Submit" value="Go!" />
  </label>
</p>

</form>
<p>&nbsp; </p>
</body>
</html>
[/code]
Try this out. Make sure you rename the fields/tablenames appropriately and create your database connection...

[code]

<?php
  session_start();

  $valid = false;
  if( isset($_SESSION['username']) )
  {
    //do whatever appropriate validation is necessary on id
    //if we encounter errors abort?
    $id = $_SESSION['username'];

    //No errors... proceed

    //connect to database

    $query = "SELECT email FROM usertable WHERE userid = $id";
    $result = mysql_query($query);
    $row = mysql_fetch_row($result);

    $email = "";
    if( $row )
    {
      $valid = true;
      $email = $row[0];
    }
    else
    {
      //Invalid username... handle error appropriately
      $valid = false;
    }

    //disconnect from database
  }
  else
  {
    //ERROR - Not logged in....
    //Redirect to login page?
    $valid = false;
  }

  if( !$valid )
  {
      //Errors, redirect....
  }
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<p>Edit Profile</p>
<form id="form1" name="form1" method="post" action="edit.php">
<p>Password :
  <input name="password" type="text" id="password" />
  <br />
  Confirm Password :
  <input name="password" type="text" id="password" />
</p>
<p>Email Address :
  <?php
      echo "<input name=\"email\" type=\"text\" id=\"email\" value=\"$email\" />\n";
  ?>
</p>
<p>
  <label>
  <input type="submit" name="Submit" value="Go!" />
  </label>
</p>

</form>
<p>&nbsp; </p>
</body>
</html>

[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.