Hi there,
i am trying actually to update the data in database. but the problem is that once i submit it tells me that its good but nothing changed , i guess that there is a problem in my : $id
Thanks in advance,
Hi there,
i am trying actually to update the data in database. but the problem is that once i submit it tells me that its good but nothing changed , i guess that there is a problem in my : $id
Thanks in advance,
Posting the actual code here would be more useful in helping you and make sure format the code if you don.
The issues that I see are
not using parameterized queries.
Not knowing if id has a value
and storing plain text passwords
<?php
$id="";
$login ="";
$email ="";
$password = "";
$firstname = "";
$lastname = "";
$job = "";
$domain = "";
$modifier="";
session_start();
include 'connection.php';
if(isset($_SESSION['login'])){
if($_SESSION['login']['rank']>1){
header("Location:user_profile.php");
}
if(isset($_GET['edit'])){
$id = $_GET['id'];
$sql = "SELECT * FROM m2lm_user WHERE id='$id' ";
$query = mysqli_query($con,$sql);
$row = mysqli_fetch_array($query);
$id = $row['id'];
$login = $row['login'];
$email = $row['email'];
$password = $row['password'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$job = $row['job'];
$domain = $row['domain'];
$modifier = true;
}
if(isset($_POST['submit']))
{
$login = $_POST['login'];
$email = $_POST['email'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$job = $_POST['job'];
$domain = $_POST['domain'];
$sql="UPDATE m2lm_user SET login='$login', email='$email', password ='$password', firstname='$firstname', lastname='$lastname', job='$job', domain='$domain' WHERE id ='$id'";
$query = mysqli_query($con,$sql);
if($query) {
echo "yesss";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit Result</title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/indexnavbar.css">
<link rel="stylesheet" href="css/indexbody.css">
</head>
<body>
<form action="modifier.php" method="post">
<div class="container">
<div class="row">
<a href="admin.php" class="btn btn-success" style="margin:10px;">Revenir </a>
</div>
<div class="row">
<?php if(isset($_REQUEST['error'])){ ?>
<div class="col-lg-12">
<span class="alert alert-danger" style="display: block;"><?php echo $_REQUEST['error']; ?></span>
</div>
<?php } ?>
</div>
<div class="row">
<?php if(isset($_REQUEST['success'])){ ?>
<div class="col-lg-12">
<span class="alert alert-success" style="display: block;"><?php echo $_REQUEST['success']; ?></span>
</div>
<?php } ?>
</div>
<div class="row">
<h2 style="margin:15px;" class="text-center">Modifier un utilisateur</h2>
</div>
<div class="row">
<div class="col-lg-12 form-group">
<input type="hidden" name="id" value="<?php $_GET['edit'] ?>" class="form-control">
</div>
</div>
<div class="row">
<div class="col-lg-12 form-group">
<input type="text" name="login" placeholder="login" required="required" value="<?php echo$login;?>" class="form-control">
</div>
</div>
<div class="row">
<div class="col-lg-12 form-group">
<input type="text" name="email" placeholder="email" required="required" value="<?php echo $email;?>" class="form-control">
</div>
</div>
<div class="row">
<div class="col-lg-12 form-group">
<input type="password" name="password" placeholder="Password" required="required" value="<?php echo $password;?>" class="form-control">
</div>
</div>
<div class="row">
<div class="col-lg-12 form-group">
<input type="text" name="firstname" placeholder="firstname" required="required" value="<?php echo $firstname;?>" class="form-control">
</div>
</div>
<div class="row">
<div class="col-lg-12 form-group">
<input type="text" name="lastname" placeholder="lastname" required="required" value="<?php echo $lastname;?>" class="form-control">
</div>
</div>
<div class="row">
<div class="col-lg-12 form-group">
<input type="text" name="job" placeholder="job" required="required" value="<?php echo $job;?>" class="form-control">
</div>
</div>
<div class="row">
<div class="col-lg-12 form-group">
<input type="text" name="domain" placeholder="domain" required="required" value="<?php echo $domain;?>" class="form-control">
</div>
</div>
<?php if($modifier==true){?>
<div class="row">
<div class="col-lg-12 form-group">
<button name="submit" type="submit" class="btn btn-success btn-block" value="modifier">Modifier</button>
</div>
<?php } ?>
</div>
</div>
</form>
</body>
</html>
You need to validate ALL inputs to a page before using them, either setting up user error messages or redirecting elsewhere. Doing this will provide a better User eXperience (UX) and it will get your code to tell you why it isn’t working. You won’t have to guess if the problem is the id, the edit action, the user rank,…
Next, you have too much code. Why does that matter? You end up with a wall of code that you cannot figure out and others don’t want to wade through trying to identify what’s actually causing the problem. Some specific things -