php mysql 更新数据的问题

我试图创建一个更新系统,但我不知道为什么我的代码不起作用。我的代码是:


<?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>

谢谢 。


临摹微笑
浏览 106回答 1
1回答

斯蒂芬大帝

你错过了。mysqli_query你的代码应该是&nbsp;<?php&nbsp;&nbsp;include "dbconnection.php";&nbsp; if(isset($_POST['submit'])){&nbsp; &nbsp; &nbsp; &nbsp; $residency_status = $_POST['residency_status'];&nbsp; $query="UPDATE profile SET&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;residential_status='$residency_status'&nbsp; WHERE id = '".user_id."'";&nbsp;&nbsp; mysqli_query($conn,$query); // $conn must be as per your `mysqli_connect` variable&nbsp; &nbsp; }&nbsp; &nbsp; header('location:profile.php');&nbsp; &nbsp; ?>
打开App,查看更多内容
随时随地看视频慕课网APP