Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
issue on updating data in php mysql

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 .

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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');
    ?>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!