我试图创建一个更新系统,但我不知道为什么我的代码不起作用。我的代码是:<?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>谢谢 。
1 回答
斯蒂芬大帝
TA贡献1827条经验 获得超8个赞
你错过了。mysqli_query你的代码应该是
<?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');
?>
- 1 回答
- 0 关注
- 97 浏览
添加回答
举报
0/150
提交
取消