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 8436193
In Process

The Archive Base Latest Questions

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

Possible Duplicate: PHP Fatal error: Call to a member function Execute() on a non-object

  • 0

Possible Duplicate:
PHP Fatal error: Call to a member function Execute() on a non-object

I’m quite new to php and mysql so please bear with me. I wrote this code but I’m getting the following error when I attempt to delete a record from my database:

<?php
require_once 'login_rankings.php';
$mysqli = new mysqli($db_hostname,$db_username,$db_password,$db_database);
if ($mysqli->connect_errno) {
echo "Failed to connect to database: " . $mysqli->connect_errno . ": " .
$mysqli->connect_error;
}

$query = "SELECT * FROM nfl";
$stmt = $mysqli->prepare($query);
$stmt->execute();
$stmt->store_result();
printf("Number of rows: %d.\n", $stmt->num_rows); echo "<br /><br /><br />";

if (isset($_POST['delete']) && isset($_POST['id']))
{
// $id = get_post('id');
$query = "DELETE FROM nfl WHERE id= :id LIMIT 1";



try{
$stmt = $mysqli->prepare($query);
$stmt->execute(array(':id' => $_POST['id']));
}catch(Exception $e){
error_log($e->getMessage() . '\r\n',3, errors.log);
}

/* not working either
  $stmt = $mysqli->prepare($query);
  $stmt->bind_param("id", $id);
  $stmt->execute(); */
}


$rows = $stmt->num_rows;
$res = $mysqli->query($query);

for ($j = 0; $j < $rows; ++$j)
{
$row = $res->fetch_assoc();
require_once 'abbrs.php';

echo <<<_END
<pre>
Last name: $row[lastname]
First name: $row[firstname]
Team: $row[team]
Position: $row[position]
Number: $row[number]
Age: $row[age]
Id: $row[id]</pre>
<form action="ranking_nfl.php" method="post">
<input type="hidden" name="delete" value="yes" />
<input type="hidden" name="id" value="$row[id]" />
<input type="submit" value="DELETE" />
</form>
_END;

}


$stmt->close();

$mysqli->close();
?>

Fatal error: Call to a member function execute() on a non-object in C:\web\project2\ranking_nfl.php on line 24

I guess that my code is lacking a function that would fetch the ‘id’ result from the form? I have no clue what I should write though.

  • 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-10T07:07:01+00:00Added an answer on June 10, 2026 at 7:07 am

    You are mixing up PDO and mysqli syntax.

    In PDO, you can use variables like :id and bind them afterwards. In mysqli you have to use a question mark and you bind your variables before the execute statement and not by feeding it an array.

    In your case (taken from the manual, I normally use PDO):

    $query = "DELETE FROM nfl WHERE id= ? LIMIT 1";
    
    try{
      $stmt = $mysqli->prepare($query);
      $stmt->bind_param('i', $_POST['id']);
      $stmt->execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Call to a member function on a non-object I try to call
Possible Duplicate: Call to a member function on a non-object What is wrong with
Possible Duplicate: PHP ToString() equivalent I get this error: Catchable fatal error: Object of
Possible Duplicate: Error : get property of non-object I am new to codeigniter model,
Possible Duplicate: Fatal error: Cannot use object of type stdClass as array in Please
Possible Duplicate: PHP function to strip tags, except a list of whitelisted tags and
Possible Duplicate: Referring to a static member of a subclass Please have a look
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: php mail() function on localhost I am using php mail(). I have
Possible Duplicate: PHP Error: mysql_fetch_array() expects parameter 1 to be resource, boolean given I

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.