2012-11-21 81 views
-1

我有2個文件edit.php和update.php edit.php第一PHP/MySQL的編輯帳戶信息

<?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> 

現在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>"; 
} 
?> 

我的繼承人問題edit.php的行說$_SESSION['id'] = '9'; 現在如果該行不說「9」,它會不會更新的ID爲9,這是我在數據庫SOFAR id爲9,如果該行不存在,它不會工作的唯一用戶的用戶根本不會更新任何信息我如何使這從當前使用拉ID [R登錄

我的繼承人登錄代碼

<?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(); 
} 
} 

?> 
+0

發表您的用戶登錄的代碼。你必須從該代碼 – GBD

+0

登錄或註冊或兩者都存儲身份證? @GBD –

+0

請貼登錄的代碼 – GBD

回答

0

寫下面一行到您的登錄文件

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

下面是完整的代碼片段

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(); 
} 

現在註釋以下行進入編輯文件。

//$_SESSION['id'] = '9'; from your edit.php 
+0

我alredy已經劇本工作的權利 –

+0

謝謝:)這麼多 –

+0

我是誰給出的解決方案爲註釋部分同一個人。如果這個答案對你有幫助,那麼接受它也會對你有所幫助 – GBD