will
will

Reputation: 49

Updating user profile details to MySQL

I have a user profile page which pulls in the logged in users information. As you can see I have set up that with the submit button the altered information gets sent to a edit_profile.php I've checked it appears with an echo. Everything arrives except password which i am not sure why.

My question is how do I get the new updated details to update the SQL.

Below is my profile page.

<!-- loads the php file into here -->
<?php  

/* This script pulls the existing name input and displays it when the user logs in. */

session_start();

include("connection.php");

$query="SELECT * FROM users WHERE id='".$_SESSION['id']."' LIMIT 1";

$result = mysqli_query($link,$query);

$row = mysqli_fetch_array($result);




?>


<!DOCTYPE html>
<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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>MyBday</title>

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

<link href='https://fonts.googleapis.com/css?family=Lato:400,300,100,300italic' rel='stylesheet' type='text/css'>

    <link rel="stylesheet" type="text/css" href="resources/css/profilestyles.css">  


<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->


</head>



 <body data-spy="scroll" data-target=".navbar-collapse">

 <div class="navbar navbar-default navbar-fixed-top">

 <div class="container">

    <div class="navbar-header">

        <button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">

            <span class="icon-bar"></span>

            <span class="icon-bar"></span>

            <span class="icon-bar"></span>

        </button>

        <a class="navbar-brand">MyBday</a>

    </div>

        <div class="collapse navbar-collapse">



           <form class="navbar-form navbar-right" method="post">

            <ul class="nav nav-pills">
              <li role="presentation"><a href="mainpage.php">My connections</a></li>
              <li role="presentation"><a href="#">World connections</a></li>
                <li role="presentation"  class="active"><a href="profile.php">Profile</a></li>    
              <li role="presentation"><a href="#">Messages</a></li>
              <li role="presentation"><a href="index.php?logout=1">Logout</a></li>
            </ul>


            </form>

        </div>


    </div>  
</div>




    <div class="container">
    <h1>Edit Profile</h1>
    <hr>
    <div class="row">
      <!-- left column -->
       <div class="col-md-3">
         <div class="text-center">
      <img src="//placehold.it/100" class="avatar img-circle" alt="avatar">
      <h6>Upload a different photo...</h6>

      <input class="form-control" type="file">
    </div>
  </div>

  <!-- edit form column -->
  <div class="col-md-9 personal-info">
    <div class="alert alert-info alert-dismissable">
      <a class="panel-close close" data-dismiss="alert">×</a> 
      <i class="fa fa-coffee"></i>
      This is an <strong>.alert</strong>. Use this to show important messages to the user.
    </div>
    <h3>Personal info</h3>

    <form class="form-horizontal" role="form" action="edit_profile.php" method="post">

      <div class="form-group">
        <label class="col-lg-3 control-label name">name:</label>
        <div class="col-lg-8">
         <input class="form-control" value="<?php echo $row['name'];?>" type="text" name="name">
        </div>
      </div>
      <div class="form-group">
        <label class="col-lg-3 control-label">Email:</label>
        <div class="col-lg-8">
          <input class="form-control" value="<?php echo $row['email'];?>" type="text" name="email">
        </div>
      </div>
      <div class="form-group">
        <label class="col-lg-3 control-label">DOB:</label>
        <div class="col-lg-8">
          <input class="form-control" value="<?php echo $row['DOB'];?>" type="date" name="DOB">
        </div>
      </div>
      <div class="form-group">
        <label class="col-lg-3 control-label">Country</label>
        <div class="col-lg-8">
          <input class="form-control" value="<?php echo $row['country'];?>" type="text" name="country">
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-3 control-label">Password:</label>
        <div class="col-md-8">
          <input class="form-control" value="<?php echo $row['pasword'];?>" placeholder="At least 8 characters and 1 cap letter" type="password" name="password">
        </div>
      </div>
      <div class="form-group">
        <label class="col-md-3 control-label">Confirm password:</label>
        <div class="col-md-8">
          <input class="form-control" value="<?php echo $row['pasword'];?>" placeholder="At least 8 characters and 1 cap letter" type="password" name="password">
        </div>
      </div>
      <div class="form-group">
        <label class="col-md-3 control-label"></label>
        <div class="col-md-8">
          <input class="btn btn-primary" value="Save Changes" type="submit">
          <span></span>
          <input class="btn btn-default" value="Cancel" type="reset">
        </div>
      </div>

    </form>
  </div>

     <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>






 </body>
</html>

When the submit button is pressed it takes you to edit_profile.php which is this at the moment.

<?php

session_start();

include("connection.php");

$query="SELECT * FROM users WHERE id='".$_SESSION['id']."' LIMIT 1";

$result = mysqli_query($link,$query);

$row = mysqli_fetch_array($result);







$name= $_POST['name']; echo $name;
$email= $_POST['email']; echo $email;
$DOB= $_POST['DOB']; echo $DOB;
$country= $_POST['country']; echo $country;
$password= $_POST['password']; echo $password;



?>

What script am i missing here to update the database. And how do I make sure I don't direct the user to a blank edit_profile.php page

Any help would be much appreciated.

Upvotes: 0

Views: 2226

Answers (1)

White Feather
White Feather

Reputation: 2783

About password, look at this:

<div class="form-group">
        <label class="col-md-3 control-label">Password:</label>
        <div class="col-md-8">
          <input class="form-control" value="<?php echo $row['pasword'];?>" placeholder="At least 8 characters and 1 cap letter" type="password" name="password">
        </div>
      </div>
      <div class="form-group">
        <label class="col-md-3 control-label">Confirm password:</label>
        <div class="col-md-8">
          <input class="form-control" value="<?php echo $row['pasword'];?>" placeholder="At least 8 characters and 1 cap letter" type="password" name="password">
        </div>
      </div>

Do you see the typing error:

$row['pasword']

I think you have an issue there, as you then use:

$password= $_POST['password']; echo $password;

Then you need to build the query for update, like:

$query = "UPDATE users column_name='".$name."', ' ... WHERE id='".$_SESSION['id']."'";

and execute it:

$result = mysqli_query($link,$query);

Use check for the success of the update, that is pretty basic:

http://www.w3schools.com/php/php_mysql_update.asp

Regards

Upvotes: 1

Related Questions