Hi. I wish to update table "users" in database(MySQL) "videos". I have posted my code below. Here I am not getting any errors but the updation is not haapenning. So, please help me to figure it out.
Thank You,
Code:
<?php
$conn = mysqli_connect("localhost", "root", "", "videos") or die(mysqli_error());
$id = (isset( $_GET["Id"]) ? $_GET["Id"] : '');
$_SESSION['Id'] = $id;
$id_exists = true;
$query = mysqli_query($conn, "SELECT * FROM users WHERE Id='$id'"); //Query for the users table
if($id_exists)
{
while($row = mysqli_fetch_array($query))
{
?>
<form action="edit.php" method="POST">
<div>
<div class="form-group">
<label>Company</label>
<input type="text" style="width:60%;" class="form-control" disabled placeholder="Company" value="CSD Technologies Pvt Ltd" />
</div>
</div>
<div>
<div class="form-group">
<label>Username</label>
<input required="required" style="width:60%;" name="Username" type="text" value="<?php echo $row['Username']; ?>" class="form-control" />
</div>
</div>
<div>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" style="width:60%;" name="Email" class="form-control" value="<?php echo $row['Email']; ?>" required="required"/>
</div>
</div>
<div>
<div class="form-group">
<label>Employee ID</label>
<input type="text" style="width:60%;" name="EmployeeID" class="form-control" value="<?php echo $row['EmployeeID']; ?>" required="required"/>
</div>
</div>
<div>
<div class="form-group">
<label>Designation</label>
<input type="text" style="width:60%;" name="Designation" required="required" class="form-control" value="<?php echo $row['Designation']; ?>"/>
</div>
</div>
<div>
<div class="form-group">
<label>Password</label>
<input type="text" style="width:60%;" name="Password" class="form-control" value="<?php echo $row['Password']; ?>" required="required"/>
</div>
</div>
<input type="submit" value="Update" class="btn btn-info btn-fill pull-right"/>
<div class="clearfix"></div>
</form>
<?php
$username = (isset($_POST['Username']) ? $_POST['Username'] : '');
$email = (isset($_POST['Email']) ? $_POST['Email'] : '');
$employee = (isset($_POST['EmployeeID']) ? $_POST['EmployeeID'] : '');
$designation = (isset($_POST['Designation']) ? $_POST['Designation'] : '');
$password = (isset($_POST['Password']) ? $_POST['Password'] : '');
}
}
else
{
Print '<h4 align="center">There is no data to be edited.</h4>';
}
?>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$conn = mysqli_connect("localhost", "root", "", "videos") or die("Connection Server" . mysqli_error());
$username = $_POST['Username'];
$email = $_POST['Email'];
$employee = $_POST['EmployeeID'];
$designation = $_POST['Designation'];
$password = $_POST['Password'];
$id = $_SESSION['Id'];
$query = mysqli_query($conn, "UPDATE users SET Username='$username', Email='$email', EmployeeID='$employee', Designation='$designation', Password='$password' WHERE Id='$id'");
echo "Records were updated successfully.";
header("location:settings.php");
}
?>
Bookmarks