亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

php mysql 更新數據的問題

php mysql 更新數據的問題

PHP
臨摹微笑 2023-07-01 17:03:10
我試圖創建一個更新系統,但我不知道為什么我的代碼不起作用。我的代碼是:<?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');

    ?>


查看完整回答
反對 回復 2023-07-01
  • 1 回答
  • 0 關注
  • 129 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號