I was trying to create an update system, but I don't know why my code is not working. My code are:
<?php
include "dbconnection.php";
if(isset($_POST['submit'])){
$residency_status = $_POST['residency_status'];
$query="UPDATE profile SET
residential_status='$residency_status'
WHERE id = '".user_id."'
";
}
header('location:profile.php');
?>
I am adding some Code from profile.php page:
<?php
session_start();
include_once ('dbconnection.php');
if(!isset($_SESSION['logged_in'])){
header("Location: login.php");
die();
}
$usrname=$_SESSION['username'];
$pasword=$_SESSION['password'];
$user_id= get_user_id($usrname, $pasword);
while($us_id= $user_id->fetch_assoc()) :
$collected_id=$us_id['id'];
$resi_status=$us_id['residential_status'];
endwhile;
?>
The code for the form is: I am trying to keep the code short to avoid
<form class="form-group row" action="get_update.php" method="POST"
enctype="multipart/form-data">
<h4>Residential Status </h4>
<div class="form-group">
<input type="radio" name="residency_status" value="yes" class=""
id=""
<?php
if ($resi_status == "yes") { ?> checked <?php }
?>
>yes
<input type="radio" name="residency_status" value="No" class="" id=""
<?php
if ($resi_status == "no" || $resi_status == "") { ?> checked
<?php } ?> >no
</div>
<br>
Thank you.
You are missing out on mysqli_query
.Your code should be as
<?php
include "dbconnection.php";
if(isset($_POST['submit'])){
$residency_status = $_POST['residency_status'];
$query="UPDATE profile SET
residential_status='$residency_status'
WHERE id = '".user_id."'";
mysqli_query($conn,$query); // $conn must be as per your `mysqli_connect` variable
}
header('location:profile.php');
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.