Hello,

I am trying to update my record but nothing is happening please help me out

update.php

<?php
    require_once("connection.php");
    if(isset($_POST["update"])) {
        $uid       = $_POST["uid"];
        $user_name = $_POST["uname"];
        $f_name    = $_POST["fname"];
        $l_name    = $_POST["lname"];
        $company   = $_POST["company"];
        $address   = $_POST["address"];
        $phone     = $_POST["phone"];
        $fax       = $_POST["fax"];
        $mobile    = $_POST["mobile"];
        $email     = $_POST["email"];

        $query_update = "UPDATE users SET user_name = {$user_name}, f_name = {$f_name}, l_name = {$l_name}, company = {$company}, phone = {$phone}, fax = {$fax}, mobile = {$mobile}, email = {$email} WHERE u_id = ".$uid;
        $query_confirm = mysqli_query($connection, $query_update);

        if($query_confirm) {
            header("Location:../profile.php");
        } else {
            header("Location:../profile_edit.php?uid=" . $uid);
        }
    }

?>

editrecord

<form method="POST" action="includes/update_profile.php">
            <div class="info">

                <input type="hidden" name="uid" value="<?php echo $user_id; ?>" />
                <label>
                    <p class="info_staic">Username</p>
                    <p class="info_dynamic"><input type="text" class="field" name="uname" value="<?php echo $user_name; ?>" /></p>
                    <div class="clear"></div>
                </label>

                <label>
                    <p class="info_staic">Company Name</p>
                    <p class="info_dynamic"><input type="text" class="field" name="coname" value="<?php echo $company; ?>" /></p>
                    <div class="clear"></div>
                </label>

                <label>
                    <p class="info_staic">Firts Name</p>
                    <p class="info_dynamic"><input type="text" class="field" name="fname" value="<?php echo $f_name; ?>" /></p>
                    <div class="clear"></div>
                </label>

                <label>
                    <p class="info_staic">Last Name</p>
                    <p class="info_dynamic"><input type="text" class="field" name="lname" value="<?php echo $l_name; ?>" /></p>
                    <div class="clear"></div>
                </label>

                <label>
                    <p class="info_staic">Address</p>
                    <p class="info_dynamic"><input type="text" class="field" name="address" value="<?php echo $address; ?>" /></p>
                    <div class="clear"></div>
                </label>

            </div><!-- End of content left-->

            <div class="info">
                <label>
                    <p class="info_staic">Phone</p>
                    <p class="info_dynamic"><input type="text" class="field" name="phone" value="<?php echo $phone; ?>" /></p>
                    <div class="clear"></div>
                </label>

                <label>
                    <p class="info_staic">Fax</p>
                    <p class="info_dynamic"><input type="text" class="field" name="fax" value="<?php echo $fax; ?>" /></p>
                    <div class="clear"></div>
                </label>

                <label>
                    <p class="info_staic">Mobile</p>
                    <p class="info_dynamic"><input type="text" class="field" name="mobile" value="<?php echo $mobile; ?>" /></p>
                    <div class="clear"></div>
                </label>

                <label>
                    <p class="info_staic">Email</p>
                    <p class="info_dynamic"><input type="text" class="field" name="email" value="<?php echo $email; ?>" /></p>
                    <div class="clear"></div>
                </label>
                <input type="submit" class="btn" value="update" name="update" />
            </div><!-- End of content right-->
            </form>

Couple things to point out, not trying to be meanie, just, I looked at your code.

First of, your form:

<form method="POST" action="includes/update_profile.php">

Redirects you to update_profile.php, it's not update.php nor editrecord.

Second of all, update.php says if(isset($_POST["update"])) but I can't spot it being set anywhere in your form. So this is never fulfilled (it's never TRUE), and nothing happens.

my mistake the file name is update_profile.php not update.php sorry about that

secondly if(isset($_POST["update"])) is listed the name of the button in the form have you noticed on the submit button <input type="submit" class="btn" value="update" name="update" />

secondly if(isset($_POST["update"])) is listed the name of the button in the form have you noticed on the submit button <input type="submit" class="btn" value="update" name="update" />

Pardon me, I haven't noticed it.

  1. Try finding out if the variables are actually saved, after if(isset($_POST["update"])) try to echo each and single one variable from $_POST array.
  2. Echo the query update, pure echo $query_update; and look up if query looks strange to you.
  3. Attempt to edit profile, and as same as on step 2, but this time, take the query and try to execute it manually on the SQL server.

There is thousands of ways why it wouldn't work (not precisely talking about your code, every program has millions of ways to go wrong), but let's make sure you can execute those 3, and maybe one of those is leading into something that would specify the "error" little more. It would also point out where exactly it's going wrong.

First of all, $company = $_POST["company"]; will having undefined post.
Then, the query $query_update = "UPDATE users SET user_name = {$user_name}, f_name = {$f_name}, l_name = {$l_name}, company = {$company}, phone = {$phone}, fax = {$fax}, mobile = {$mobile}, email = {$email} WHERE u_id = ".$uid; try echo it and direct paste to mysql admin to test if the query work(Based on my understanding, it won't work as I believe the user_name etc will be varchar and will not accept user_name = {$user_name})

Hi

can you check line 13

<p class="info_dynamic"><input type="text" class="field" name="coname" value="<?php echo $company; ?>" /></p>

replace the name as company or replace

$company = $_POST['coname'];

Good work thanks to you all got the error fixed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.