Jump to content

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


forumnz

Recommended Posts

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Yes I do have phpMyAdmin.

Code.

[code]<?php
  session_start();
 
  $con = mysql_connect("localhost","####","####");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

  $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 members 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....
  }
?>
[/code]
Link to comment
Share on other sites

That's not an error, that's output based on the echo command that I had you put in. That's the actual query being sent to the database.

Put // in front of the echo command I just had you put in (comment it out).

And then change this:

$query = "SELECT email FROM usertable WHERE userid = $id";

to this:

$query = "SELECT email FROM usertable WHERE userid = '$id'";
Link to comment
Share on other sites

Worked.

Okay, uncomment the echo $query thing again.

Should look like this:

echo $query;

And right after $result = mysql_query($query);

put:

if( mysql_errno() )
{
  echo "\n\nERROR: " . mysql_error();
}

Then please paste me the new code.
Link to comment
Share on other sites

Here you go:

[code]<?php
  session_start();
 
  $con = mysql_connect("localhost","####","####");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

  $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 username FROM members WHERE userid = '$id'";echo $query;
    $result = mysql_query($query);
if( mysql_errno() )
{
  echo "\n\nERROR: " . mysql_error();
}
    $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....
  }
?>[/code]
Link to comment
Share on other sites

PM me your username.

Paste that in overwriting everything in your edit.php file and resave it.

[code]

<?php
  session_start();
 
  $con = mysql_connect("localhost","####","####");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

  $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 username FROM members WHERE id = '$id'";
//echo $query;
    $result = mysql_query($query);
if( mysql_errno() )
{
  echo "\n\nERROR: " . mysql_error();
}
    $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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.