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

  • Home
  • SEARCH
  • 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 8681203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:26:49+00:00 2026-06-12T21:26:49+00:00

I am trying to retrieve the data from mysql database using PDO but I

  • 0

I am trying to retrieve the data from mysql database using PDO but I am getting errors.

Here is the code

 <form id="form" action="sum1.php" method="post">
 <td><p align="center"> IDNO : <input type="text" name="id" id="id" maxlength="10"</p></td>
 <input type="submit" id="submit" class='btnExample' value="Click here to get your Result">
  </form> 
  <?PHP 
  $dbhost     = "localhost";
  $dbname     = "demo";
  $dbuser     = "admin";
  $dbpass     = "123456";
  $db = new PDO("mysql:host=$dbhost;dbname=$dbname", "$dbuser", "$dbpass");
  $id = $_POST['id']; 
  $add = $db->prepare("SELECT SUM(tech) AS tech4 FROM (
  (SELECT SUM(tm) AS tech FROM jbit WHERE htno > :id)
  UNION ALL
  (SELECT SUM(tm) AS tech FROM hmm WHERE htno > :id))t1");
  $add -> execute(array('id'=>$id));
  $result3 = $db->query($add);
  echo " <center><table id='mytable' cellspacing='0'  border=3 align=center> 
  <tr><TH scope='col'>Total Marks</TH> </tr><center>"; 
  while ($row1 = $result3->fetch(PDO::FETCH_ASSOC))
  {
   echo "<tr>"; 
   echo "<td align=center>" . $row1['tech4']. "</td>";
   echo "</tr>";
   }
   $result3->closeCursor();
   $db = null;
   ?>

ERRORS I am getting

Warning: PDO::query() expects parameter 1 to be string, object given in /home/nhtsoft/public_html/engineershub/sum1.php on line 17

and

Fatal error: Call to a member function fetch() on a non-object in /home/nhtsoft/public_html/engineershub/sum1.php on line 20

17th Line is

$result3 = $db->query($add);

20th line is

while ($row1 = $result3->fetch(PDO::FETCH_ASSOC))

Any ideas?

  • 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-12T21:26:51+00:00Added an answer on June 12, 2026 at 9:26 pm

    First of all fix this

     $add -> execute(array('id'=>$id)); 
      //and remove 
     $result3 = $db->query($add);
    

    And use

     $add -> execute(array(':id'=>$id));
      while($result=$add->fetch(PDO::FETCH_ASSOC))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to retrieve data from mysql database using PDO but DATABASE NOT
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I am trying to retrieve specific data from my MySQL database by passing the
I am trying to retrieve CLOB data from our Oracle database. the code is
I am trying to retrieve data into an xml tag from the database using
I am trying to figure out how to retrieve data from a MySQL database
I'm trying to retrieve hierarchical data from a table but am failing to do
I'm trying to retrieve record data from an MS-Access database and store it into
I am trying to transfer a table from MySQL to MSSQL using the data
I am trying to retrieve data from mysql then display it on android listview.

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.