如何在PHP中将用户名显示为值

时间:2014-06-17 14:02:49

标签: php

我想知道如何在文本框中显示用户的用户名。我这样做是因为当他们编辑设置并更新它们时,它会将其电子邮件等更新为数据库中的空白字段:

这是我想要改变的代码

<input type="text" name="name" class="form-control" id="name" class="required" value="<? echo $row_settings['full_name']; ?>" />

我想制作`value = $ row_settings ['full_name'];' 我怎么能这样做?

所有代码:

    <?php 
/********************** MYSETTINGS.PHP**************************
This updates user settings and password
************************************************************/
include 'dbc.php';
page_protect();

$err = array();
$msg = array();

if($_POST['doUpdate'] == 'Update')  
{


$rs_pwd = mysql_query("select pwd from users where id='$_SESSION[user_id]'");
list($old) = mysql_fetch_row($rs_pwd);
$old_salt = substr($old,0,9);

//check for old password in md5 format
  if($old === PwdHash($_POST['pwd_old'],$old_salt))
  {
  $newsha1 = PwdHash($_POST['pwd_new']);
  mysql_query("update users set pwd='$newsha1' where id='$_SESSION[user_id]'");
  $msg[] = "Your new password is updated";
  //header("Location: mysettings.php?msg=Your new password is updated");
  } else
  {
   $err[] = "Your old password is invalid";
   //header("Location: mysettings.php?msg=Your old password is invalid");
  }

}

if($_POST['doSave'] == 'Save')  
{
// Filter POST data for harmful code (sanitize)
foreach($_POST as $key => $value) {
  $data[$key] = filter($value);
}


mysql_query("UPDATE users SET
      `full_name` = '$data[name]',
      `address` = '$data[address]',
      `tel` = '$data[tel]',
      `user_email` = '$data[user_email]',
      `user_name` = '$data[user]',
      `fax` = '$data[fax]',
      `country` = '$data[country]',
      `website` = '$data[web]'
       WHERE id='$_SESSION[user_id]'
      ") or die(mysql_error());

//header("Location: mysettings.php?msg=Profile Sucessfully saved");
$msg[] = "Profile Sucessfully saved";
 }

$rs_settings = mysql_query("select * from users where id='$_SESSION[user_id]'"); 
?>

<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../../assets/ico/favicon.ico">
    <script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script>
  <script>
  $(document).ready(function(){
    $("#myform").validate();
   $("#pform").validate();
  });
  </script>

    <title>The Infibox - Edit Profile</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/indexSettings.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <?php if (isset($_SESSION['user_id'])) {?>
          <a class="navbar-brand" href="#">Infibox</a>
          <a class="navbar-brand">|</a>
          <a class="navbar-brand" href="/recruitment">My Account</a>
          <a class="navbar-brand" href="#">Settings</a>
          <a class="navbar-brand" href="#">Logout</a>
          <?php }

          ?>
  <?php 
if (checkAdmin()) {
/*******************************END**************************/
?>
      <a class="navbar-brand" href="admin.php">Admin CP </a>
    <?php } ?>
        </div>
        <div class="navbar-collapse collapse">
          <form class="navbar-form navbar-right" role="form">
            <div class="form-group">
              <input type="text" placeholder="Email" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" placeholder="Password" class="form-control">
            </div>
            <button type="submit" class="btn btn-success">Sign in</button>
          </form>
        </div><!--/.navbar-collapse -->
      </div>
    </div>

    <!-- Main jumbotron for a primary marketing message or call to action -->


      <p> 
        <?php 
  if(!empty($err))  {
     echo "<div class=\"msg\">";
    foreach ($err as $e) {
      echo "* Error - $e <br>";
      }
    echo "</div>";  
     }
     if(!empty($msg))  {
      echo "<div class=\"msg\">" . $msg[0] . "</div>";

     }
    ?>
      </p>

<!-- Show their details inside the correct box. E.g. their first name they registered with will be shown inside the "First Name" box. Does not occur with passwords. -->
<center>
<div class="wrapper">
<h2 class="title">Edit Profile</h2>
<?php while ($row_settings = mysql_fetch_array($rs_settings)) ?>
<form action="mysettings1.php" method="post" name="myform" id="myform">
<div class="input-group" id="fname">
  <span class="input-group-addon">Name</span>
  <input type="text" name="name" class="form-control" id="name" class="required" value="<? echo $row_settings['full_name']; ?>" />
</div>
<div class="input-group">
  <span class="input-group-addon">Customer ID</span>
  <input type="text" name="user" class="form-control" maxlength="6" id="web2" value="<? echo $row_settings['user_name']; ?>">
</div>
<div class="input-group">
  <span class="input-group-addon">Email</span>
  <input type="text" class="form-control" name="user_email" id="web3"  value="<? echo $row_settings['user_email']; ?>">
</div>
<div class="input-group">
  <span class="input-group-addon">Add Paypal Email</span>
  <input type="text" class="form-control" name="tel" id="tel" class="required" value="<? echo $row_settings['tel']; ?>">
</div>
<div class="btn-group">
  <input name="doSave" type="submit" id="doSave" value="Save" class="btn btn-success">
</div>
<hr class="hr" />
<!-- When Changing Password Old Password Must Be Entered + Correct-->
<h2 class="title2">Change Password</h2>
<div class="input-group">
  <span class="input-group-addon">Old Password</span>
  <input type="password" class="form-control" name="pwd_old" class="required password" id="pwd_old" >
</div>
<div class="input-group">
  <span class="input-group-addon">New Password</span>
  <input type="password" class="form-control" name="pwd_new" class="required password" id="pwd_new" >
</div>
<div class="btn-group">
  <input name="doUpdate" type="submit" id="doUpdate" value="Update" class="btn btn-success">
</div>

</div>
</center>
</form>
<!-- ##################################################################################### -->
<!-- ##################################################################################### -->
</div>
</center>




    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

1 个答案:

答案 0 :(得分:0)

您不需要while循环: 变化

<?php while ($row_settings = mysql_fetch_array($rs_settings)) ?> 

<?php $row_settings = mysql_fetch_array($rs_settings); ?>