0

我希望在文本框中获取用户的所有详细信息,以根据存储在会话中的用户名相应地编辑用户配置文件我不希望哪个语句是错误的我无法在文本框中获取值。请帮我。

配置文件.php

<?php

include('connection.php');
//include('validation1.php');   
session_start();
if( !empty($_SESSION['username']) && isset($_SESSION['username']))  
{  
 $username=$_SESSION['username'];
 $checkinfo = mysql_query("SELECT * FROM profile WHERE username=".'"$username"');
//$result=mysql_fetch_array($checkinfo);
while($result = mysql_fetch_array($checkinfo,MYSQL_ASSOC)){
$name =($result['name']);
    $address =($result['address']);
    $contact =($result['contact']);

    $state =($result['state']);
    $city = ($result['city']);
    $username =($result['uname']);
    $oldpass = ($result['opass']);

}
}
if (isset($_POST['submit'])) 
{
    $name =($_POST['name_txt']);
    $address =($_POST['address_txt']);
    $contact =($_POST['contact_txt']);
    $gender = ($_POST['gender']);
    $country = ($_POST['country']);
    $state =($_POST['state_txt']);
    $city = ($_POST['city_txt']);
    $username =($_POST['uname_txt']);
    $oldpass = ($_POST['opass_txt']);
    $newpass = ($_POST['npass_txt']);

    $insquery="UPDATE INTO profile(name, address, contact,gender, country, state, city,username,opassword,npassword) VALUES     ('$name','$address','$contact','$gender','$country','$state','$city','$username','$oldpass','$newpass')";
    $result=mysql_query($insquery); 

   // header("location:display.php");     
     if(!$insquery)  
    {  
    echo "Error Save [".mysql_error()."]";  
    }  
    /*else
    {
        // header("location:display.php");
    }*/
}
 ?>
<body>
<form id="form1" name="form1" method="post" action="">
<div align="center">
Registration Form
</div>
<div align="right">
          <?php if(isset($_SESSION['username']))
            {
                $s="Hello,".$_SESSION["username"];
                $r=$_SESSION["userrole"];
                echo $s;
            }    ?><a href='logout.php' id='logout'>Logout</a>
</div>
<table>
<tr>
<td><label>Name:</label></td>
<td><input name="name_atxt" type="text" id="name_atxt" value="<?php echo $name; ?>" /></td>
</tr>

<tr>
<td><label>Address:</label></td>
<td><textarea name="address_txt" cols="40" rows="4" value="<?php echo $address; ?>"></textarea></td>
</tr>

<tr>
<td><label>Contact:</label></td>
<td><input name="contact_txt" type="text" id="contact_ntxt" value="<?php echo $contact; ?>" /></td>
</tr>

<tr>
<td><label>Gender:</label>
<td>
<input type=radio name=gender value="male" id=male >Male</br>
<input type=radio name=gender value="female" id=female >Female</br></td>
</td>
</tr>

<tr>
<td><label>Country:</label></td>
<td><select name="country_select" id="country_select">
<option value="0">--select a country--</option>
<option value="India">India</option>
<option value="USA">USA</option>
<option value="UK">UK</option>
<option value="Australia">Australia</option>
</select></td>
</tr>

<tr>
<td><label>State:</label></td>
<td><input name="state_atxt" type="text" id="state_atxt" value="<?php echo $state; ?>"/></td>
</tr>

<tr>
<td><label>City:</label></td>
<td><input name="city_atxt" type="text" id="city_atxt" value="<?php echo $city; ?>" /></td>
</tr>

<tr>
<td><label>Username:</label></td>
<td><input name="uname_txt" type="text" id="uname_txt" value="<?php echo $username; ?>" /></td>
</tr>

<tr>
<td><label>Old Password:</label></td>
<td><input name="opass_txt" type="password" id="opass_txt" value="<?php echo $oldpass; ?>"   /></td>
</tr>

<tr>
<td><label>New Password:</label></td>
<td><input name="npass_txt" type="text" id="npass_txt" /></td>
</tr>

<tr>
<td><input type="submit" name="submit" value="Submit" id="btn1" /></td>
<td><input name="reset_btn" type="reset" value="Reset" /></td>
</tr>
</table>

</form>
</body>

我希望已经存储在数据库中的值应该在会话中的特定用户的文本框中获取,而不是在文本框中获取值。

4

2 回答 2

1
$checkinfo = mysql_query("SELECT * FROM profile WHERE username=".'"$username"');

应该

$checkinfo = mysql_query("SELECT * FROM profile WHERE username='$username'");

你的UPDATE语法也不正确

于 2013-04-29T03:22:41.533 回答
0

SQL 更新语句:

 UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value    
于 2013-04-29T03:13:28.683 回答