+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: PHP error report script - PDO::prepare not working

  1. #1
    as4s1n's Avatar
    as4s1n is offline x10 Sophmore as4s1n is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Washington State
    Posts
    174

    PHP error report script - PDO::prepare not working

    I have a script set up so that if there is an error on any page a PM is sent directly to me. The only problem is, that whenever there is an error I always get the same error:

    Fatal error: Call to a member function prepare() on a non-object in home/sikuneh/public_html/inc/SL_modules.php on line 26

    The only problem is, everything checks out and looks perfectly fine.

    PHP:
    PHP Code:
        $closingString "Error with script. The webmaster has already been notified.";
        echo 
    $closingString;
        
        
    $sth $dbh->prepare("INSERT INTO mail VALUES(0,:T,:F,:S,:M,now(),0)");
            
    $sth->bindValue(":T",'10');
            
    $sth->bindValue(":F",'10');
            
    $sth->bindValue(":S",'Error(s)');
            
    $sth->bindValue(":M",$logstring);
        
    $sth->execute(); 
    DB structure:
    Id, toUser, from, subject, message, date, read

    Please help.
    There is no such thing as a "stupid question," there are only "stupid people" who don't ask them.

  2. #2
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: PHP error report script - PDO::prepare not working

    Have you actually created the PDO object called $dbh? This error usually arises from something going awry in the connection phase.
    Last edited by lemon-tree; 06-16-2010 at 06:15 AM.

  3. #3
    as4s1n's Avatar
    as4s1n is offline x10 Sophmore as4s1n is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Washington State
    Posts
    174

    Re: PHP error report script - PDO::prepare not working

    Yeah, it's working on all my other pages... Wait a second, if I call this page using an AJAXREQUEST can it still use variables defined on an include that was called at the top of the page (the one making the ajax request)?
    Last edited by as4s1n; 06-16-2010 at 10:06 AM.
    There is no such thing as a "stupid question," there are only "stupid people" who don't ask them.

  4. #4
    dlukin is offline x10 Lieutenant dlukin is on a distinguished road
    Join Date
    Oct 2009
    Posts
    427

    Re: PHP error report script - PDO::prepare not working

    You mean you have foo.php making an Ajax request to bar.php?

    They will be two different instances. bar.php will not be able to access anything from when foo.php ran (except, of course, values passed in the query string or POST data).

  5. #5
    zapzack is offline x10 Elder zapzack is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    606

    Re: PHP error report script - PDO::prepare not working

    I don't think so.. If your saying your using ajax to include a php page that includes variables from the page your including it from..

  6. #6
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: PHP error report script - PDO::prepare not working

    The variables cannot travel over as the execution of the first page has finished before the second page is being called by the AJAX. You will need to re-specify the PDO connection and then you can transfer data to the browser in the AJAX as either plain text or in XML format.

  7. #7
    as4s1n's Avatar
    as4s1n is offline x10 Sophmore as4s1n is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Washington State
    Posts
    174

    Re: PHP error report script - PDO::prepare not working

    No, it still doesn't work. I have no idea what's wrong still. I referenced both my module page and the dbc page on each but it still doesn't work.
    There is no such thing as a "stupid question," there are only "stupid people" who don't ask them.

  8. #8
    dlukin is offline x10 Lieutenant dlukin is on a distinguished road
    Join Date
    Oct 2009
    Posts
    427

    Re: PHP error report script - PDO::prepare not working

    No code.
    No url.
    No information on the AJAX call.
    No information if the same error is happening.

    How do you expect help?

  9. #9
    as4s1n's Avatar
    as4s1n is offline x10 Sophmore as4s1n is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Washington State
    Posts
    174

    Re: PHP error report script - PDO::prepare not working

    Ok, here goes:

    Requested page (via ajax):
    PHP Code:
    <?php #Admin delete post 
    DEFINE("CURPAGE","DELETEPOSTADMIN.php");
    session_start();
    include(
    "dbc.php");
    include(
    "../SL_modules.php");
    if(!isset(
    $_SESSION['loggedin']) || $_SESSION['loggedin'] != 'Admin Sikuneh') {
        echo 
    "You do not have permission to view this page";
    } else {
    $postID $_GET['id'];

    $sth $dbh->prepare("SELECT * FROM submissions WHERE id = '$postID'");
    $sth->execute();
    if(
    $sth->columncount() === 0)
        echo 
    "Error: Cannot find post.";
    else {
        try{
        
    $sth2 $dbh->prepare("UPDATE submissions SET status = '2' WHERE id = '$postID'");
        
    $sth2->execute();
        } catch(
    PDOException $e) {
        
    writeError($e->getMessage(),CURPAGE);
        }
            try{
            echo 
    "Post $postID has been deleted.";
    #Problem here
            
    $sth3 $dbh->query("SELECT submitter FROM submissions WHERE id = '$postID'");
            while(
    $row=$sth3->fetch()) 
                
    $poster $row['submitter'];
            
    $sth4 $dbh->query("SELECT id FROM users WHERE username = '$poster'");
            while(
    $row=$sth4->fetch())
                
    $posterID $row['id'];
            
    $mailMessage "Your post has been deleted by the administrator.";
            
    $mailSubject "Post deleted";
            
    $sth4 $dbh->exec("INSERT INTO mail(id,toUser,'from',subject,message,date,read) VALUES(0,'$posterID','10','$mailSubject','$mailMessage',now(),0)");
            } catch(
    PDOException $e) {
            
    writeError($e->getMessage(),CURPAGE);
            }

    }
    }
    ?>
    Page that calls the Ajax:
    PHP Code:
    <?php if(!isset($_SESSION['admin_login'])) { ?>
    You do not have permission to view this page
    <?php } else {?>
    include("dbc.php");
    <h2 style="margin-top:0; padding-top:5px;">Administration for Submission Lore</h2>
    <style type="text/css">
    table#admin_entries a:link,
    table#admin_entries a:visited
    {
    color:#FFF;
    }
    </style>
    <script type="text/javascript">
    function createRequest() {
      try {
        request = new XMLHttpRequest();
      } catch (tryMS) {
        try {
          request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (otherMS) {
          try {
            request = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (failed) {
            request = null;
          }
        }
      }    
      return request;
    }

    function confirmEntry(id,box){

    request = createRequest();
       var url= 'inc/admin/addEntry.php?id='+id+'&&session=Admin Sikuneh&&sid='+Math.random();   
       request.onreadystatechange = function() {
         if (request.readyState == 4) {
            if (request.status == 200) {
               document.getElementById(box).innerHTML = request.responseText;
               setTimeout("updateStatus()",5000);
            }
         }
      }
    request.open("GET", url, true);
    request.send(null);
    }

    function deleteEntry(id,box){

    request = createRequest();
        var url= 'inc/admin/deletePostAdmin.php?id='+id+'&&session=Admin Sikuneh&&sid='+Math.random();
          request.onreadystatechange = function() {
         if (request.readyState == 4) {
            if (request.status == 200) {
               document.getElementById(box).innerHTML = request.responseText;
               setTimeout("updateStatus()",5000);
            }
         }
      }

    request.open("GET", url, true);
    request.send(null);
    }

    function restoreEntry(id,box){

    request = createRequest();
       var url = 'inc/admin/restorePostAdmin.php?id='+id+'&&session=Admin Sikuneh&&sid='+Math.random();
          request.onreadystatechange = function() {
         if (request.readyState == 4) {
            if (request.status == 200) {
               document.getElementById(box).innerHTML = request.responseText;
               setTimeout("updateStatus()",5000);
            }
         }
      }

    request.open("GET", url, true);
    request.send(null);
    }

    function placeOnHold(id,box) {

    request = createRequest();
       var url = 'inc/admin/onHold.php?id='+id+'&&session=Admin Sikuneh&&sid='+Math.random();
          request.onreadystatechange = function() {
         if (request.readyState == 4) {
            if (request.status == 200) {
               document.getElementById(box).innerHTML = request.responseText;
               setTimeout("updateStatus()",5000);
            }
         }
      }
    request.open("GET", url, true);
    request.send(null);
    }

    function updateStatus(){

    request = createRequest();
        var url= 'inc/admin/admin_checkentries2.php?sid='+Math.random();
          request.onreadystatechange = function() {
         if (request.readyState == 4) {
            if (request.status == 200) {
               document.getElementById("place").innerHTML = request.responseText;
            }
         }
      }
     request.open("GET", url, true);
    request.send(null);

    }

    window.onload=updateStatus;
    </script>
    <div id="place" style="width:100%"></div>

    <h2>Most recent errors:</h2>
    <div style="font-size:10px;">
    <?php 
    include("Logs/errors.log");
    ?>
    </div>
    <?php ?>
    Database connection page (dbc.php):
    PHP Code:
    <?php
    $host 
    "localhost";
    $dbname dbname;
    $username dbusername;
    $password dbpassword;
       try
       {
         
    $dbh = new PDO("mysql:host=$host;dbname=$dbname"$username,$password);
         
    $dbh->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
       }
       catch (
    PDOException $e)
       {
         print (
    "Could not connect to server.\n");
         
    writeError($e->getMessage());
       }
       
    ?>
    Module which is giving trouble:
    PHP Code:
    include("dbc.php");
    # Error write script
    function writeError($error,$page) {
        if(
    $page == null
            
    $page "INDEX.PHP";
        
    # Get the current date
        
    $date date('r');
        
    # Where, when and what
        
    $logstring "Error on page $page at line $location on $date ERROR: $error\n";
        
    # Open the file
        
    $fp fopen("http://sikuneh.x10hosting.com/Logs/errors.log",'a');
        
    # Write to it
        
    fwrite($fp,$logstring);
        
    # Close
        
    fclose($fp);

        
    $closingString "Error with script. The webmaster has already been notified."
        echo 
    $closingString
         
        
    $sth $dbh->prepare("INSERT INTO mail VALUES(0,:T,:F,:S,:M,now(),0)"); 
            
    $sth->bindValue(":T",'10'); 
            
    $sth->bindValue(":F",'10'); 
            
    $sth->bindValue(":S",'Error(s)'); 
            
    $sth->bindValue(":M",$logstring); 
        
    $sth->execute(); 

    I would like to give you a live URL but this is on the admin page and it would take me a day or two to recreate an example. Yes it is the same error. GL.
    There is no such thing as a "stupid question," there are only "stupid people" who don't ask them.

  10. #10
    dlukin is offline x10 Lieutenant dlukin is on a distinguished road
    Join Date
    Oct 2009
    Posts
    427

    Re: PHP error report script - PDO::prepare not working

    Quote Originally Posted by as4s1n View Post


    Page that calls the Ajax:
    PHP Code:
    <?php if(!isset($_SESSION['admin_login'])) { ?>
    You do not have permission to view this page
    <?php } else {?>
    include("dbc.php");  <<<<<<<<<<<<<< ??????
    <h2 style="margin-top:0; padding-top:5px;">Administration for Submission Lore</h2>
    <style type="text/css">
    That "include" is outside php tags. I have no idea why that is there.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. pb PHP using mysql prepare statement
    By fomalhaut in forum Programming Help
    Replies: 3
    Last Post: 11-03-2009, 03:58 AM
  2. BEGOBY.com - Helping users prepare for their DEATH
    By begoby in forum Review My Site
    Replies: 3
    Last Post: 05-17-2009, 09:52 PM
  3. BEGOBY.com - Helping users prepare for their DEATH
    By begoby in forum Link Exchange
    Replies: 0
    Last Post: 05-14-2009, 07:57 AM
  4. PHP Forum Script Not Working, NO error, PHP V2
    By matfor1 in forum Free Hosting
    Replies: 3
    Last Post: 11-15-2007, 06:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers