-1

i have 2 files edit.php and update.php edit.php first

<?php
session_start();
$_SESSION['id'] = '9';
$id = $_SESSION["id"];
$username = $_POST["username"];
$fname = $_POST["fname"];
$password = $_POST["password"];
$email = $_POST["email"];

mysql_connect('mysql13.000webhost.com', 'a2670376_Users', 'PASSWORD') or     die(mysql_error());
echo "MySQL Connection Established! <br>";

mysql_select_db("a2670376_Pass") or die(mysql_error());
echo "Database Found!<br>";

$query = "UPDATE members SET username = '$username', fname = '$fname', 
password = '$password' WHERE id = '$id'";

$res = mysql_query($query);

if ($res)
echo "<p>Record Updated $rows[id]<p>";
else
echo "Problem updating record MySQL Error: " . mysql_error();
?>

<form action="update.php" method="post">
<input type="hidden" name="id" value="<?=$id;?>"/>
ScreenName:<br> <input type='text' name='username' id='username' maxlength='25'    style='width:247px' name="username" value="<?=$username;?>"/><br>
FullName:<br> <input type='text' name='fname' id='fname' maxlength='20' style='width:248px' name="fname" value="<?=$fname;?>"/><br>
Email:<br> <input type='text' name='email' id='email' maxlength='50' style='width:250px' name="email" value="<?=$email;?>"/><br>
Password:<br> <input type='text' name='password' id='password' maxlength='25' style='width:251px' value="<?=$password;?>"/><br>
<input type="Submit">
</form>

now update.php

<?php
session_start();
mysql_connect('mysql13.000webhost.com', 'a2670376_Users', 'PASSWORD') or     die(mysql_error());
mysql_select_db("a2670376_Pass") or die(mysql_error());
$id = (int)$_SESSION["id"] = $_SESSION['id'];

$username = mysql_real_escape_string($_POST["username"]);
$fname = mysql_real_escape_string($_POST["fname"]);
$email = mysql_real_escape_string($_POST["email"]);
$password = mysql_real_escape_string($_POST["password"]);


$query="UPDATE members
SET username = '$username', fname = '$fname', email = '$email', password = '$password'
WHERE id = '$id'";


mysql_query($query)or die(mysql_error());
if(mysql_affected_rows()>=1){
echo "<p>($id) Record Updated<p>";
}else{
echo "<p>($id) Not Updated $_SESSION[username]<p>";
}
?> 

heres my problem in edit.php the line that says $_SESSION['id'] = '9'; now if that line does not say '9' it will not update the user that has the id 9 thats the only user i have sofar the id in the database is 9 if that line is not there it will not work at all it wont update any ones information how do i make this pull the id from the current user logged in

heres my login code

<?php
session_start();
// Check if he wants to login:
if (!empty($_POST[username]))
{
require_once("connect.php");

// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
                        WHERE username = '$_POST[username]'
                        AND password = '$_POST[password]'")
or die ("<center>Error - Couldn't login user!!");

$row = mysql_fetch_array($query)
or die ("<center>Error - Couldn't login user!!");

if (!empty($row[username])) // he got it.
{
    $_SESSION[username] = $row[username];
    echo "<center>Welcome $_POST[username]! You've been successfully logged in.   <br><h2 style='color: Yellow;'>REDIRECTING.....</H2><br><img    src='http://i1261.photobucket.com/albums/ii586/jacob1899/ajax-loader-1.gif'></center>      <meta http-equiv='REFRESH' content='1;url=/index.htm'>";
    exit();
}
else // bad info.
{
    echo "<center>Error - Couldn't login user!!";
    exit();
}
}

?>
Jacob Tonna
  • 17
  • 2
  • 4
  • 13

1 Answers1

0

write following line into your login file

$_SESSION['id'] = $row[id]; 

Here is complete snippet code

if (!empty($row[username])) // he got it.
{
    $_SESSION[username] = $row[username];
    $_SESSION['id'] = $row[id]; 
    echo "<center>Welcome $_POST[username]! You've been successfully logged in.   <br><h2 style='color: Yellow;'>REDIRECTING.....</H2><br><img    src='http://i1261.photobucket.com/albums/ii586/jacob1899/ajax-loader-1.gif'></center>      <meta http-equiv='REFRESH' content='1;url=/index.htm'>";
    exit();
}
else // bad info.
{
    echo "<center>Error - Couldn't login user!!";
    exit();
}

Now comment following line into edit file.

//$_SESSION['id'] = '9'; from your edit.php 
GBD
  • 15,847
  • 2
  • 46
  • 50
  • i am same person who given solution into comments section. if this answer helped to you, then it's good accept it it will help you as well – GBD Nov 21 '12 at 10:37