Jump to content

not able to read data from database


shan
Go to solution Solved by Jacques1,

Recommended Posts

hi guys im actually perplexed with this problem where im not able to read anything from DB, when i var dump the object it just outputs bool(false). dont know where im going wrong, Pl help me

here is the code logic for status_list page where status_reply resides which i want to read from DB and display it:-

$status2view=$project->statusView($f_uname);

    foreach($status2view as $row){
           //print_r($row);
           $updateid=$row['update_id'];
     
    
//gives output on var_dump
  // print_r($updateid); (gives output)
$status_reply_=$project->reply2StatusView($updateid);
        print_r($status_reply_);

        foreach ($status_reply_ as $row) {
                
                $status_reply_id=$row['update_id'];
                $reply_author=$row['author'];
                $reply_d=htmlentities($row['update_body']);
                $reply_data=  stripslashes($reply_d);
                $reply_t=  htmlentities($row['title']);
                $reply_title=  stripslashes($reply_t);
                $account_name=$row['account_name'];
               $reply_date=$row['time'];
               $reply_delete_button="";
               if ($reply_author==$session_uname || $account_name==$session_uname) {
                   $reply_delete_button="<li><span id='$status_reply_id' class='delete_reply_btn glyphicon glyphicon-remove'><a href='#' title='Delete this comment'>Remove X</a></span></li>";
               }
              $status_replies="<div  class='replyboxes pull-left reply".$status_reply_id."'><b>Reply by<a href='search_results.php?u=".$reply_author."'>".$reply_author."</a><span class='pull-right'>".$reply_date ."</pan><legend>"
                       . "<b class='caret'>
                           <button type='button' class='btn btn-danger dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true' ><span class='glyphicon glyphicon-edit'></span>
                        <ul class='dropdown-menu'>".$reply_delete_button
                      . "<li><a href='#' class='hidden_text_area glyphicon glyphicon-pencil reply".$status_reply_id."' title='Edit this comment' >Edit</a></li>"
                      . "<li><a href='report.php?u='".$reply_author."'>Report</a><li></ul>"
                      . "</button></b></legend><br>".  html_entity_decode($reply_data)."";
            }
        
}       
     foreach ($status2view as $row1) {
        
         //got values here.
                $updateid=$row1['update_id'];
                $account_name=$row1['account_name'];
                $os_id=$row1['os_id'];
                $author=$row1['author'];
                $post_date=$row1['time'];
                $title= stripslashes($row1['title']);
                $data= stripslashes($row1['update_body']);
                $statusdeletebutton='';
                //insert_status_ui script to get message.
        
                if($isowner=="yes"){
 $statusui_edit="<div type='".$updateid."' class='hidden_edit_4_session session_editor".$updateid." jumbotron'>"
            . "<a href='#' type='".$updateid."' class='pull-right close_edit' title='Close without editing'>Close X</a>"
            . "<input type='text' class='form-control title_s_edit title_s_".$updateid."' name='status_title' value='".html_entity_decode($title)."' placeholder='Title' >"
            . "<span> </span>"
            . "<textarea id='wall_edit_1' type='".$updateid."' rows='5' cols='50'  class='session_edit text_value_".$updateid."' wrap='hard' placeholder='whats up ".$session_uname."'>
             ".html_entity_decode($data)."</textarea><br>"
            . "<button style='float:right;' value='".$updateid."' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div>" ;
 
    
}
 elseif ($is_friend==TRUE&&$session_uname!=$f_uname) {
     
     
     $statusui_edit="<div type='".$updateid."' class='hidden_edit_4_friend friend_editor".$updateid." jumbotron'>"
             . "<a title='Close without editing' type='".$updateid."' href='#' class='pull-right close_edit_f'>Close X</a>"
               . "<input type='text' class='form-control title_f_edit title_f_".$updateid."''  name='status_title' value='".html_entity_decode($title)."' placeholder='Title'><br>"
               . "<div> </div>"
            . "<textarea id='wall_edit_2' value='' type='".$updateid."' rows='5' cols='50'  class='friend_edit update_friend_".$updateid."' placeholder='hi ".$session_uname." want to say something to ".$f_uname.". '>"
               .html_entity_decode($data)."</textarea><br>"
               . "<button style='float:right;' value='".$updateid."' type='c' class='btn btn-warning btn-large btn-lg post-f-edit'>Update</button></form></div>";
 }
 
                if ($author==$session_uname || $account_name==$session_uname) {
                $statusdeletebutton='<li>'
                           . '<a href="#" type="'.$updateid.'" class="delete_4_session hidden_text_delete_'.$updateid.' glyphicon glyphicon-trash delete_reply_btn" title="Delete this status and its replies">Remove</a></li>';
                }
                if($isowner=="yes"){
                $status_list= $statusui_edit.'<div attr="'.$updateid.'" type="'.$updateid.'" class="statusboxes status_'.$updateid.'  jumbotron">'
                        . '<h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left">'
                        . '<div id="'.$updateid.'" class="title_s_2copy" value="'.html_entity_decode($title).'">'.html_entity_decode($title).'</div></h3>'
                        . '<span class="pull-right">'
                        . '<div class="dropdown">'
                        . '<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"  >'
                        . '<span class="glyphicon glyphicon-edit"></span></button>'
                        . '<ul class="dropdown-menu">'
                        . '<li><a href="#" attr="'.$updateid.'" type="'.$updateid.'" class="edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li>'.$statusdeletebutton.'</ul></div></span><br><hr>'
                        . '<legend><span class=" data_s_2copy" type="'.$updateid.'" value="'.html_entity_decode($data).'">'
                        . html_entity_decode($data).'</span><br><br></legend><b style="text-align:right; color:black;"><small>Posted by:-  <a href="search_results.php?u='.$author.'">'.$author.   '</a>   '.$post_date.'</small></b>'
                        . '<br><p>'.$status_replies.'</p><br>';

                if ($is_friend==TRUE||$session_uname==$f_uname) {
                    $status_list.= '<textarea id="'.$updateid.'"  class="status_reply_'.$updateid.' input-custom2" placeholder="comment\'s"></textarea>'
                            . '<button id="reply_btn_'.$updateid.'" attr="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm reply_btn reply_'.$updateid.'">Reply</button></div>';
                    }
                    
                    }elseif ($is_friend==TRUE&&$session_uname!=$f_uname) {
                    $status_list= $statusui_edit.'<div attr="'.$updateid.'" type="'.$updateid.'" class="statusboxes status_'.$updateid.'  jumbotron">'
                        . '<h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left">'
                        . '<div id="'.$updateid.'" class="title_s_2copy" value="'.html_entity_decode($title).'">'.html_entity_decode($title).'</div></h3><br><hr>'
                        . '<legend><span class=" data_s_2copy" type="'.$updateid.'" value="'.html_entity_decode($data).'">'
                        . html_entity_decode($data).'</span><br><br></legend><b style="text-align:right; color:black;"><small>Posted by:-  <a href="search_results.php?u='.$author.'">'.$author.   '</a>   '.$post_date.'</small></b>'
                        . '<br><p>'.$status_replies.'</p><br>';
                             $status_list.= '<textarea id="'.$updateid.'"  class="status_update input-custom2" placeholder="comment\'s"></textarea>'
                            . '<button id="reply_btn'.$updateid.'"  attr="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm reply_btn reply_'.$updateid.'">Reply</button></div>';
                    
                    
                }
                echo $status_list;
                }  
                
     

the above code is called in home and search results page through include_once function.

if you need any details please do ask me for it

Link to comment
Share on other sites

When you throw a bunch of class-related code at us and give us way too much to look at without fully understanding the goal, it makes us not want to help you.

 

Try debugging each of your methods to be sure that they are doing EXACTLY what you expect.  Once you are happy with them, do the same debugging with your surrounding logic to be sure that you are giving those methods what they expect and that the returns are what you expect still.

 

When you get down to one single point of contention - show us that roadblock and tell us what is not working.

Link to comment
Share on other sites

@ginerjm sorry about the mess.

it is not working in the instantiated object.

$status_reply_=$project->reply2StatusView($updateid);

its outputting bool(false) when var_dumped.

(edited)

here is the method:

public function reply2StatusView($updateid){
        $stmth=  $this->_db->prepare("select * from updates where update_id=:statusid and type='b' order by time asc");
        $stmth->bindparam(":statusid", $updateid);
        $stmth->execute();
     return $stmth->fetchAll(PDO::FETCH_ASSOC);
Edited by shan
Link to comment
Share on other sites

So your returned value is False.  That implies that the execute failed.  Never write code that "does" something that could fail without checking the result.  Especially a class where you plan on using it a lot.  So - test the execute and display the error (on screen during development or in your error_log once in production).

Link to comment
Share on other sites

it would seem that you have removed the code you previously had that was setting the PDO error mode to exceptions. the false value being returned means that the execute statement failed and an exception wasn't thrown for the error.

 

so, why did you remove (or not copy) the error setting you did have in your code?

  • Like 1
Link to comment
Share on other sites

it would seem that you have removed the code you previously had that was setting the PDO error mode to exceptions. the false value being returned means that the execute statement failed and an exception wasn't thrown for the error.

 

so, why did you remove (or not copy) the error setting you did have in your code?

actually i changed it because of  an advice given to me by a friend.

 

And even after changing the code im not getting output. any help would be appreciated:

 

here is the updated code:

include '../includes/dbconfig.inc.php';

$status2view=$project->statusView($_SESSION['uname']);

    foreach($status2view as $row){
           //print_r($row);
           $updateid=$row['update_id'];
     
    
//gives output on var_dump
  // print_r($updateid); (gives output)
$stmth= $conn->prepare("select * from updates where update_id=:statusid and type='b' order by time asc");
        $stmth->bindparam(":statusid", $updateid);
        $stmth->execute();
        $status_reply_=$stmth->fetchAll(PDO::FETCH_ASSOC);
        print_r($status_reply_);//no output
        foreach ($status_reply_ as $row) {
                
                $status_reply_id=$row['update_id'];
                $reply_author=$row['author'];
                $reply_d=htmlentities($row['update_body']);
                $reply_data=  stripslashes($reply_d);
                $reply_t=  htmlentities($row['title']);
                $reply_title=  stripslashes($reply_t);
                $account_name=$row['account_name'];
               $reply_date=$row['time'];
               $reply_delete_button="";
               if ($reply_author==$session_uname || $account_name==$session_uname) {
                   $reply_delete_button="<li><span id='$status_reply_id' class='delete_reply_btn glyphicon glyphicon-remove'><a href='#' title='Delete this comment'>Remove X</a></span></li>";
               }
              $status_replies="<div  class='replyboxes pull-left reply".$status_reply_id."'><b>Reply by<a href='search_results.php?u=".$reply_author."'>".$reply_author."</a><span class='pull-right'>".$reply_date ."</pan><legend>"
                       . "<b class='caret'>
                           <button type='button' class='btn btn-danger dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true' ><span class='glyphicon glyphicon-edit'></span>
                        <ul class='dropdown-menu'>".$reply_delete_button
                      . "<li><a href='#' class='hidden_text_area glyphicon glyphicon-pencil reply".$status_reply_id."' title='Edit this comment' >Edit</a></li>"
                      . "<li><a href='report.php?u='".$reply_author."'>Report</a><li></ul>"
                      . "</button></b></legend><br>".  html_entity_decode($reply_data)."";
            }
        
}    
Link to comment
Share on other sites

So did you activate PDO exceptions again? Is your PHP error reporting on? What do you mean by “no output”? An empty array? The boolean false?

 

We cannot magically fix your code just by looking at it. Since only you can run it, you must provide us with the relevant info.

i'm sorry for being hasty bro, it doesnt throw any errors, except the empty array. and btw i changed the code as above still no luck with it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.