Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8479775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:07:35+00:00 2026-06-10T19:07:35+00:00

I am using PHP to try and update information I have in a mysqli

  • 0

I am using PHP to try and update information I have in a mysqli table. I have decided to try and use mysqli rather than mysql. Unfortunately I cant seem to find my answer anywhere because im also trying to complete it Procedural style, as I have no knowledge of OOP and all tutorials (that i have found) are in OOP.

Below is the script I have created. I have added comments to say what I think each command is doing.

<?php    
DEFINE('DB_USER', 'root');
DEFINE('DB_PASS', 'password');
DEFINE('DB_NAME', 'test');
DEFINE('DB_HOST', 'localhost');

//connect to db
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die(mysqli_connect_error($dbc));
mysqli_set_charset($dbc, 'utf8');

//form not submitted
if(!isset($_POST['submit'])){

    $q = "SELECT * FROM people WHERE people_id = $_GET[id]";//compares id in database with id in address bar
    $r = mysqli_query($dbc, $q);//query the database
    $person = mysqli_fetch_array($r, MYSQLI_ASSOC);//returns results from the databse in the form of an array

}else{//form submitted

    $q = "SELECT * FROM people WHERE people_id = $_POST[id]";//compares id in database with id in form
    $r2 = mysqli_query($dbc, $q);//query the database
    $person = mysqli_fetch_array($r2, MYSQLI_ASSOC);//returns results from the database in an array

    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $age = $_POST['age'];
    $hobby = $_POST['hobby'];
    $id = $_POST['id'];

    //mysqli code to update the database
    $update = "UPDATE people
               SET    people_fname = $fname,
                      people_lname = $lname,
                      people_age = $age,
                      people_hobby = $hobby
               WHERE  people_id = $id";

    //the query that updates the database
    $r = @mysqli_query($dbc, $update) or die(mysqli_error($r));

    //1 row changed then echo the home page link
    if(mysqli_affected_rows($dbc) == 1){    
        echo "<a href=\"index.php\">home page</a>";
    }
}
?>

The update form

<form action="update.php" method="post">
    <p>First name<input type="text" name="fname" value="<?php echo "$person[people_fname]" ?>" /></p>
    <p>Last name<input type="text" name="lname" value="<?php echo "$person[people_lname]" ?>" /></p>
    <p>Your age<input type="text" name="age" value="<?php echo "$person[people_age]" ?>" /></p>
    <p>Your hobby<input type="text" name="hobby" value="<?php echo "$person[people_hobby]" ?>" /></p>
    <input type="hidden" name="id" value="<?php echo $_GET['id'] ?>" />        
    <input type="submit" name="submit" value="MODIFY" />
</form>`

When I submit the form I get the following error message

Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\sandbox\update.php on line 39

I realize this is telling me the issue is with

$r = @mysqli_query($dbc, $update) or die(mysqli_error($r));

So I have tried to put the sqli code in as the second parameter (i realize this is the same as putting the variable in, but it was a last resort), but it didn’t seem right and still didn’t work. I have also looked a php.net but couldn’t work out the answer from the example they have given

Please advise, I thought this was meant to be simple?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:07:36+00:00Added an answer on June 10, 2026 at 7:07 pm

    Don’t pass $r to mysqli_error. It accepts an optional mysql link, but not a query result anyway.

    In your case, the query is executed. That evaluates to false, which is assigned to $r. The assignment evaluates to false, causing you to call die(mysqli_error($r)) with $r being false.

    I think you meant to pass $dbc to mysqli_error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm using PHP/MySQL and I have a tbl_profile table with the following fields:
I try to use amazon API using PHP. If I use print_r($parsed_xml->Items->Item->ItemAttributes) it show
I have built a site using php and want to try keep it one
Im using Debian testing, i have installed php-cli and when i try to execute
Using PHP, and MySql, I am trying to implement this rather snazzy in-place editor
Whenever i try using php with lighttpd on my iphone i get error 500
I am using the PHP SDK to try and post a simple action using
I'm creating a login for a website using PHP but when I try to
When I try to include a file using include_once in php which shows warning
When I try to remove my PHP extensions from all my files using my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.