我试图创建一个更新系统,但我不知道为什么我的代码不起作用。我的代码是:
<?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');
?>
我从 profile.php 页面添加一些代码:
<?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;
?>
表单的代码是:我试图保持代码简短以避免
<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>
谢谢 。
斯蒂芬大帝