Jump to content

Search the Community

Showing results for tags 'pdo'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. Not sure why I can't get this been trying to figure it out all evening :/ The included smconfig.php contains my database password. Any ideas, I know it's gotta be easy, I must be missing something. PDO connect.php: <?php session_start(); include 'smconfig.php'; $db_host = "127.0.0.1"; $db_username = "root"; $db_pass = "$dbpass"; $db_name = "golden_wand"; // PDO CONNECT $db = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); ?> http://www.golden-wand.com/members/tester.php <?php include "../Scripts/connect.php"; $email = "test@gmail.com"; $stmt1 = $db->prepare("SELECT id, activated, username, email, password, token FROM members WHERE email=:email LIMIT 1"); $stmt1->bindParam(':email',$email,PDO::PARAM_STR); $stmt1->execute(); $count = $stmt1->rowCount(); if($count > 0){ while($row = $stmt1->fetch(PDO::FETCH_ASSOC)){ $uid = $row['id']; $username = $row['username']; $email = $row['email']; $hash = $row['password']; $activated = $row['activated']; $token = $row['token']; } } echo "Before: <br>"; echo 'UID = '.$uid; echo '<br>Token = '.$token; echo '<br>Activated = '.$activated; echo '<br>Hash = '.$hash; $activated="1"; $token = "md5($hash)"; try{ $db->beginTransaction(); $updateSQL = $db->prepare("UPDATE members SET activated=':activated' WHERE id=':uid' LIMIT 1"); $updateSQL->bindParam(':activated',$activated,PDO::PARAM_STR); $updateSQL->bindParam(':uid',$uid,PDO::PARAM_INT); $updateSQL->execute(); $db->commit(); echo "<br><br><br><br>Update Successful<br><br><br><br>"; } catch(PDOException $e){ $db->rollback(); echo "<br><br><br><br>Update Failed<br><br><br><br>"; } $stmt2 = $db->prepare("SELECT id, activated, username, email, password, token FROM members WHERE email=:email LIMIT 1"); $stmt2->bindParam(':email',$email,PDO::PARAM_STR); $stmt2->execute(); $count = $stmt2->rowCount(); if($count > 0){ while($row = $stmt2->fetch(PDO::FETCH_ASSOC)){ $uid = $row['id']; $username = $row['username']; $email = $row['email']; $hash = $row['password']; $activated = $row['activated']; $token = $row['token']; } } echo "After: <br>"; echo 'UID = '.$uid; echo '<br>Token = '.$token; echo '<br>Activated = '.$activated; echo '<br>Hash = '.$hash; ?> I own this site: http://www.golden-wand.com/phpfreaks.txt
  2. Trying to finish up this PHP section to this login and sign up section. At the moment I'm having issues with the sign up, it's throwing me an error when I signed up, not sure exactly what happened because it did work once and only once. My error throws on line 206 the beginTransaction line. http://www.golden-wand.com/members/contact-test.php try{ $db->beginTransaction(); $ipaddress = getenv('REMOTE_ADDR'); $stmt2 = $db->prepare("INSERT INTO members (firstname, lastname, username, email, password, signup_date, ipaddress) VALUES (:fistname, :lastname, :username, :email, :bcrypt, now(), :ipaddress)"); $stmt2->bindParam(':fistname',$fistname,PDO::PARAM_STR); $stmt2->bindParam(':lastname',$lastname,PDO::PARAM_STR); $stmt2->bindParam(':username',$username,PDO::PARAM_STR); $stmt2->bindParam(':email',$email,PDO::PARAM_STR); $stmt2->bindParam(':bcrypt',$bcrypt,PDO::PARAM_STR); $stmt2->bindParam(':ipaddress',$ipaddress,PDO::PARAM_INT); $stmt2->execute(); /// Get the last id inserted to the db which is now this users id for activation and member folder creation //// $lastId = $db->lastInsertId(); $stmt3 = $db->prepare("INSERT INTO activate (user, token) VALUES ('$lastId', :token)"); $stmt3->bindValue(':token',$token,PDO::PARAM_STR); $stmt3->execute(); // Create our email body $link = 'http://golden-wand.com/Scripts/activate.php?user='.$lastId.'&token='.$token.''; $data = "Thanks for registering an account at Golden Wand! We are glad you decided to join us. Theres just one last step to set up your account. Please click the link below to confirm your identity and get started. If the link below is not active please copy and paste it into your browser address bar. <br><br> $link"; // Create the Transport $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl') ->setUsername($user_name) ->setPassword($pass_word); // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); // Create a message $message = Swift_Message::newInstance('Sign Up') ->setFrom(array('support@golden-wand.com' => 'From: Auto Resposder @ Golden Wand')) ->setTo(array('ditto.100@gmail.com' => 'Recipient')) ->setSubject('IMPORTANT: Activate your Golden Wand Account') ->setBody($data, 'text/html') ; // Send the message $result = $mailer->send($message); $db->commit(); $msg .= "<li class='success'>Thanks for joining! Check your email in a few moments to activate your account so that you may log in. See you on the site!</li>"; $db = null; } catch(PDOException $e){ $db->rollBack(); echo $e->getMessage(); $db = null; } I own this site http://www.golden-wand.com/phpfreaks.txt
  3. How do i bind values to a variable which is partially processed with diffrent statements and then concatenated using php .= operator below is piece of code $wher = ''; now I have added few varibles to $wher like if (!empty($_SESSION['advs']['title'])) { $wher .= '('; if (isset($_SESSION['advs']['desc'])) { $wher .= "(au.description like '%" . $system->cleanvars($_SESSION['advs']['title']) . "%') OR "; } $wher .= "(au.title like '%" . $system->cleanvars($_SESSION['advs']['title']) . "%' OR au.id = " . intval($_SESSION['advs']['title']) . ")) AND "; } more addition to $wher if (isset($_SESSION['advs']['buyitnow'])) { $wher .= "(au.buy_now > 0 AND (au.bn_only = 'y' OR au.bn_only = 'n' && (au.num_bids = 0 OR (au.reserve_price > 0 AND au.current_bid < au.reserve_price)))) AND "; } if (isset($_SESSION['advs']['buyitnowonly'])) { $wher .= "(au.bn_only = 'y') AND "; } if (!empty($_SESSION['advs']['zipcode'])) { $userjoin = "LEFT JOIN " . $DBPrefix . "users u ON (u.id = au.user)"; $wher .= "(u.zip LIKE '%" . $system->cleanvars($_SESSION['advs']['zipcode']) . "%') AND "; } now I am using $wher in database SELECT query like // get total number of records $query = "SELECT count(*) AS total FROM " . $DBPrefix . "auctions au " . $userjoin . " WHERE au.suspended = 0 AND ". $wher . $ora . " au.starts <= " . $NOW . " ORDER BY " . $by; $wher is being used in SQL select query. My problem is, How do I put placeholders to $wher and bind the values??
  4. hi, guys after taking jacques1 advice on having a relational scheme for my db to fetch results for my project, i was finally able to produce results for the users timeline, but now the problem arises with the feeds page where i'm not able to make the comments to display to its appropriate posts. cant figure out where the bug is arising. if you can help me it would be much appreciated. other than the comments problem there seems to be no errors displaying on the page.i'll attach a DB schema here for you all to look in to. here is the code: <?php $statusui_edit=""; $status2view=$project->statusView($_SESSION['uname']); foreach($status2view as $row){ $status_replies=""; $updateid=$row['update_id']; $account_name=$row['account_name']; $os_id=$row['os_id']; $author=$row['author']; $post_date=$row['time']; $title= stripslashes($row['title']); $data= stripslashes($row['update_body']); $statusdeletebutton=''; $sql1="select * from updates,comment_update where comment_update.os_id like updates.update_id and comment_update.type like 'b'"; $sql2="select * from updates left join comment_update on comment_update.os_id = updates.update_id where updates.update_id=:statusid"; $stmth=$conn->prepare($sql2); // $stmth->bindparam(":either",$_SESSION['uname']); $stmth->bindparam(":statusid",$updateid); $stmth->execute(); $status_reply= $stmth->fetchAll(PDO::FETCH_ASSOC); foreach ($status_reply as $row1) { $status_reply_id=$row1['comment_id']; $reply_author=$row1['author']; $reply_d=htmlentities($row1['comment_body']); $reply_data= stripslashes($reply_d); $reply_osid=$row1['os_id']; $reply_date=$row1['time']; $reply_delete_button=""; if ($reply_author==$_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>"; } if ($sql2==TRUE) { $status_replies.="<div class='replyboxes pull-left reply_".$status_reply_id."'>Reply by:-<a href='home.php?u=".$reply_author."'>".$reply_author."</a>" . "<span class='pull-right'>".$reply_date . "<b class='caret'> <small><span class='btn-xs 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>" . "</span></span></small></b><br><legend>". html_entity_decode($reply_data)."</legend><br></div>"; } else { $status_replies.=""; } } //insert_status_ui script to get message. 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>'; $edit_btn='<li>' . '<a href="#" attr="'.$updateid.'" type="'.$updateid.'" class="edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li>'; } $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">' .$edit_btn.'<br>'. $statusdeletebutton.'</ul></div></span><br><hr>' . '<legend><span class=" data_s_2copy" type="'.$updateid.'" >' . html_entity_decode($data).'</span><br><br></legend><b style="text-align:right; color:black;"><small>Posted by:- <a href="home.php?u='.$author.'">'.$author. '</a> '.$post_date.'</small></b>' . '<br><p>'.$status_replies.'</p><br>'; $status_list.= '<textarea id="reply_textarea_'.$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>'; $friends = array(); // select friend_one, friend_two from friends where (friend_one = 1 or friend_two =1) and accepted = 1 $stmt= $conn->prepare("select friend_one from friends where friend_two=:session and accepted='1'"); $stmt->bindparam(":session",$_SESSION['uname']); $stmt->execute(); foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $r) { array_push($friends, $r["friend_one"]); } $stmth1= $conn->prepare("select friend_two from friends where friend_one=:session and accepted='1'"); $stmth1->bindparam(":session",$_SESSION['uname']); $stmth1->execute(); foreach ($stmth1->fetchAll(PDO::FETCH_ASSOC) as $r1) { array_push($friends, $r1["friend_two"]); for($i = 0; $i < count($friends); $i++){ $friend = $friends[$i]; $sql1="select* from updates where account_name=:friend and type='a' or account_name=:friend and type='c' order by time desc"; $stmt=$conn->prepare($sql1); $stmt->bindValue(":friend",$friend); $stmt->execute(); $feeds=$stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($feeds as $val) { $updateid=$val['update_id']; $account_name=$val['account_name']; $os_id=$val['os_id']; $author=$val['author']; $post_date=$val['time']; $title= stripslashes($val['title']); $data= stripslashes($val['update_body']); $statusdeletebutton=''; 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>'; } $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.'" >' . html_entity_decode($data).'</span><br><br></legend><b style="text-align:right; color:black;"><small>Posted by:- <a href="home.php?u='.$author.'">'.$author. '</a> '.$post_date.'</small></b>' . '<br><p>'.$status_replies.'</p><br>'; $status_list.= '<textarea id="reply_textarea_'.$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>'; } } } echo $status_list; } ?>
  5. hi, guys i'm trying to create a commenting system to posts in a example site. And i can't seem to print the exact comments to its original post. i created two tables updates and comment_update and kept os_id as the common table row, where it is refering to update_id of updates table. everything seems ok except for the loops which is screwing up the output. Any advice on how to rectify it as i tried with while & other loops everything gives the same problem. here is my code for that logic: <?php $status_replies=""; $statusui_edit=""; $status2view=$project->statusView($_SESSION['uname']); foreach($status2view as $row){ $updateid=$row['update_id']; $account_name=$row['account_name']; $os_id=$row['os_id']; $author=$row['author']; $post_date=$row['time']; $title= stripslashes($row['title']); $data= stripslashes($row['update_body']); $statusdeletebutton=''; $sql1="select * from updates,comment_update where comment_update.os_id like updates.update_id and comment_update.type like 'b'"; $sql2="select * from updates left join comment_update using (os_id) where comment_update.os_id=:statusid "; $stmth=$conn->prepare($sql2); // $stmth->bindparam(":either",$_SESSION['uname']); //$stmth->bindparam(":statusid",$updateid); $stmth->execute(array( ":statusid"=>$updateid)); $status_reply= $stmth->fetchAll(PDO::FETCH_ASSOC); foreach ($status_reply as $row) { $status_reply_id=$row['comment_id']; $reply_author=$row['author']; $reply_d=htmlentities($row['comment_body']); $reply_data= stripslashes($reply_d); $reply_osid=$row['os_id']; $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>"; } if ($updateid==$reply_osid) { $status_replies="<div class='replyboxes pull-left reply_".$status_reply_id."'>Reply by:-<a href='search_results.php?u=".$reply_author."'>".$reply_author."</a>" . "<span class='pull-right'>".$reply_date . "<b class='caret'> <small><span class='btn-xs 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>" . "</span></span></small></b><br><legend>". html_entity_decode($reply_data)."</legend><br></div>"; } else { $status_replies=""; } } //insert_status_ui script to get message. 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>'; } $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.'" >' . 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="reply_textarea_'.$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>'; echo $status_list; } ?>
  6. I’m trying to post data to a MySQL DB table. In fact I’m working on learning how to interact with a DB from a web form. I had it almost working a couple of times but when I start trying to tweak it, it all goes awry. But the consistent issue that keeps popping up is an issue with “ Incorrect integer value: ':age' for column 'age' at row 1 “ This table "people" in the DB "peoples" has 3 columns; “id”, “name”, “age”. I was able to get it to work as long as I stuck with a numbered array. But when I try to use an associative array I start getting the error. The only thing I can think of is the id field in the DB. That maybe that’s throwing off my row count. Though obviously I don’t want to display the id field data in my webpage. So here’s the basic code I’m trying to make work. <?php include 'connForm.php'; ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>PDO with Forms</title> </head> <body> <form method="post" action="connform.php"> Name: <input type="text" id="name" name="name" /> <br /> Age: <input type="text" id="age" name="age" /> <br /> <input type="submit" value="add" /> <br /> </form> <br /> <br /> </body> </html> <?php echo htmlentities($row['name']). " is " . htmlentities($row['age']). " years old " . "<br>"; ?> conform.php contains the following code… <?php try { $db = new PDO('mysql:host=127.0.0.1;dbname=peoples', 'root', 'r00t'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo $e->getMessage(); echo '<br>'; echo 'You may have a problem'; } $stmt = $db->query('SELECT * FROM people'); $result = $stmt->fetchAll (); foreach($result as $row) { $name = htmlentities($row ['name']); $age = htmlentities($row ['age']); } if(isset($_POST ['name']) ) { $name = $_POST ['name']; $age = $_POST ['age']; $stmt = $db ->prepare ("INSERT INTO people (name, age) VALUES (':name', ':age') "); $stmt ->bindValue(':name', $_POST ['name']); $stmt ->bindValue(':age', $_POST ['age']); $stmt ->execute (); } ?> One of the biggest problems with trying to learn anything from the internet isthat everybody has their own way of doing everything and each one wants to show off their precieved expertise. This means that trying to learn anything means trying to distill all these dispirit methods into the simplest cut & dried method I can manage. oddly of all the tutorials out there on YouTube dealing with PHP and PDO there are almost none dealing with PDO and web forms. I say "none" I mean, like 2 maybe 3 though I don't think I've found #3.
  7. 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
  8. hi, guys im trying to echo out results of a particular variable in my search_results.php file where i want to actually display the status of a friend which isn't showing up but is showing up in home.php page which handles the session user data. though i tried some variations it isn't of any help. The satusui variable which has the same logic works well but not the status_list variable for the friend in search_results page. please, help me to build the conversation system. code in status_list page:- $status2view=$project->statusView($f_uname); foreach($status2view as $row){ //print_r($row); $id=$row['update_id']; //gives output on var_dump $status_replies_=$project->reply2StatusView($id); foreach ($status_replies_ 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 id='".$status_reply_id."' class='replyboxes'><b>Reply by<a href='search_results.php?u=".$reply_author."'>".$reply_author."</a>".$reply_date ."<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' 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' >" . "<div> </div>" . "<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>"; } 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).'" style="font-size:9px; margin-bottom:0px; margin-top:0px; text-align:left; color:black;">' . 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>'.$status_replies.'<br>'; if ($is_friend==TRUE||$session_uname==$f_uname) { $status_list.= '<textarea id="'.$updateid.'" class="status_update input-custom2" placeholder="comment\'s"></textarea>' . '<button id="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm">Reply</button></div>'; } echo $status_list; }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>' . '<legend><span class=" data_s_2copy" type="'.$updateid.'" value="'.html_entity_decode($data).'" style="font-size:9px; margin-bottom:0px; margin-top:0px; text-align:left; color:black;">' . 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>'.$status_replies.'<br>'; $status_list.= '<textarea id="'.$updateid.'" class="status_update input-custom2" placeholder="comment\'s"></textarea>' . '<button id="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm">Reply</button></div></div>'; echo $status_list; } } code for search_results page where the statuslist is included:- if($isowner=="yes"){ $statusui="<div class='jumbotron'><input type='text' class='form-control title_s' name='status_title' placeholder='Title ' ><br>" . "<textarea id='wall_id_1' class='update_session' placeholder='whats up ".$session_uname."'>" . "</textarea>" . "<button style='float:right;' type='a' class='btn btn-warning btn btn-large btn-lg post-s'>Post</button></div>"; $statusui_edit="<div attr='".$updateid."' class='hidden_edit_4_session session_edit".$updateid." jumbotron'>" . "<a href='#' class='pull-right close_edit' title='Close without editing'>Close X</a>" . "<input type='text' class='form-control title_s_edit' name='status_title' value='".html_entity_decode($title)."' placeholder='Title' >" . "<div> </div>" . "<textarea id='wall_edit_1' class='session_edit' placeholder='whats up ".$session_uname."'> ".html_entity_decode($data)."</textarea><br>" . "<button style='float:right;' 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="<div class='jumbotron'><input type='text' class='form-control title_f' name='status_title' placeholder='Title'><br>" . "<textarea id='wall_id_2' type='c' class='status_4_friend' style='' placeholder='hi ".$session_uname." want to say something to ".$f_uname.". '>" . "</textarea><br>" . "<button style='float:right;' type='c' class='btn btn-warning btn-large btn-lg post-f'>Post</button></div>"; $statusui_edit="<div attr='".$updateid."' class='hidden_edit_4_friend friend_edit".$updateid." jumbotron'>" . "<a title='Close without editing' href='#' class='pull-right close_edit_f'>Close X</a>" . "<input type='text' class='form-control title_f_edit' name='status_title' value='".html_entity_decode($title)."' placeholder='Title'><br>" . "<textarea id='wall_edit_2' value='' class='update_4_expresspad'placeholder='hi ".$session_uname." want to say something to ".$f_uname.". '>" .html_entity_decode($data)."</textarea><br>" . "<button style='float:right;' type='c' class='btn btn-warning btn-large btn-lg post-f-edit'>Update</button>"; } ?> <div class="container-fluid"> <br><div class="row"> </div><br> <div class="row"> <div class="col-sm-2"> <p>Friends list:</p> <?php include_once 'notification/friend_list.php'; echo $friends_html; ?> </div> <div class="col-lg-8"> <div class="tab-content"> <ul class="nav nav-tabs"> <li class="active"><a href="#tabs-1" data-toggle="tab" class="profile">Profile</a></li> <li><a href="#tabs-2" data-toggle="tab"class="articles">Status</a></li> <li><a href="#tabs-4"data-toggle="tab" class="gallery_photos">Gallery</a></li> <li><a href="#tabs-5" data-toggle="tab" class="videos">Videos</a></li> </ul> <div id="tabs-1" class="tab-pane fade profile1 active in"> <?php echo '<table border="0"><tr width="20%"><td>Profile Photo</td><td>' . $friend_button . '</td></tr> <tr><td></td><td>' . $block_button . '</td></tr> <tr width="100%"><td width="20%"></td><td width="55%"><p>Full Name:' . $fname_s . ' ' . $lname_s . '<br> </td><td width="20%"></td></tr> </table>'; ?> </div> <div id="tabs-2" class="tab-pane fade articles">
  9. hi, guys i have a problem in outputting the id in php. what i'm trying to do is create a article and when the user clicks the edit button the text area shows up for editing while the original article hides. i'm using both jquery and php to do it. the problem is that when the user clicks the edit button the hidden text area doesn't showup when i looked in to the browser source i found that the id is not outputting in the hidden textarea. so, please guide me on how to print the id in the hidden area. here is the code for jquery : $(".hidden_text_edit").click(function(){ var id=$(this).attr("id"); $(".hidden_edit_4_session").find("id").show(); var hide_status=$(".statusboxes").attr('type'); var title=$(".title_s_2copy").attr('type'); var data=$(".data_s_2copy").attr('type'); $(hide_status).hide(); //tinyMCE.get('.hidden_edit_4_session').setContent(data); $(".title_s_edit").val(title); }); $(".close_edit").click(function(){ $(".hidden_edit_4_session").hide(); var hide_status=$(".statusboxes").attr('div', 'type'); $(hide_status).show(); }); code for article and hidden text area logic: <?php if(isset($_SESSION['app'])){ $statusui="<div class='jumbotron'><input type='text' class='form-control title_s' name='status_title' placeholder='Title ' ><br>" . "<textarea id='wall_id_1' class='update_session' placeholder='whats up ".$session_uname."'>" . "</textarea>" . "<button style='float:right;' type='a' class='btn btn-warning btn btn-large btn-lg post-s'>Post</button></div>"; $statusui_edit="<div id=".$updateid." class='hidden_edit_4_session".$updateid." jumbotron'><a href='#' class='pull-right close_edit' title='Close without editing'>Close X</a><input type='text' class='form-control title_s_edit' name='status_title' value='".html_entity_decode($title)."' placeholder='Title' ><div> </div>" . "<textarea id='wall_edit_1' value='".html_entity_decode($data)."' class='session_edit' placeholder='whats up ".$session_uname."'>" . "" .html_entity_decode($data)."</textarea><br>" . "<button style='float:right;' 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="<input type='text' class='form-control title_f' name='status_title' placeholder='Title'><br>" . "<textarea id='wall_id_1' type='c' value='".html_entity_decode($data)." class='status_4_expresspad_friend' style='' placeholder='hi ".$session_uname." want to say something to ".$f_uname.". '>" . "</textarea><br>" . "<button style='float:right;' class='btn btn-warning btn-large btn-lg post-f'>Post</button><br><br><br><div> </div>"; $statusui_edit="<div class='hidden_edit_4_friend jumbotron'><a title='Close without editing' href='#' class='pull-right close_edit_f'>Close X</a><input type='text' class='form-control title_f_edit' name='status_title' value='".html_entity_decode($title)."' placeholder='Title'><br>" . "<textarea id='wall_edit_2' value='".html_entity_decode($data)."' class='update_4_expresspad'placeholder='hi ".$session_uname." want to say something to ".$f_uname.". '>" . "</textarea><br>" . "<button style='float:right;' type='c' class='btn btn-warning btn-large btn-lg post-f-edit'>Update</button>"; } ?> here is the code where the status list is outputting in a loop with the hidden text area's logic: <?php $status2view=$project->statusView($session_uname, $f_uname); //gives output on var dump #row vars to extract user's update data. foreach($status2view as $row){ $id=$row['update_id']; $status_replies_=$project->reply2StatusView($id); foreach ($status_replies_ 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 id='".$status_reply_id."' class='replyboxes'><b>Reply by<a href='search_results.php?u=".$reply_author."'>".$reply_author."</a>".$reply_date ."<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' 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= $row1['title']; $data= $row1['update_body']; $statusdeletebutton=''; if ($author==$session_uname || $account_name==$session_uname) { $statusdeletebutton='<li>' . '<a href="#" id="'.$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>'; } $status_list= '<div id="'.$updateid.'" type="'.$updateid.'" class="statusboxes 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="#" id="'.$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><span class="pull-left data_s_2copy" id="'.$updateid.'" value="'.html_entity_decode($data).'" style="font-size:9px; margin-bottom:0px; margin-top:0px; text-align:left; color:black;">' . html_entity_decode($data).'</span><br><br><hr><b style="text-align:right; color:black;"><small>Posted by:- <a href="search_results.php?u='.$author.'">'.$author. '</a> '.$post_date.'</small></b>' . '<br>'.$status_replies.'<br>'.$statusui_edit; if ($is_friend==TRUE||$session_uname==$f_uname) { $status_list.= '<textarea id="'.$updateid.'" class="status_update input-custom2" placeholder="comment\'s"></textarea>' . '<button id="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm">Reply</button></div>'; } echo $status_list; }
  10. hi, guys im actually following a tutorial here and i'm perplexed with this error, where there is no output for one object inside a loop. since the tutorial is procedural code and im doing it in oop i dont know where im going wrong.please help me. the code for the complete article.php is here: <?php include_once '../includes/dbconfig.inc.php'; $status2view=$project->statusView($session_uname, $f_uname); //gives output on var dump #row vars to extract user's update data. for ($i= 0; $i >=0 ; $i++) { $id=array_column($status2view ,'update_id'); //gives output on var_dump if ($id==NULL) { break; }else { continue; } $status_replies_=$project->reply2StatusView($id[$i]); var_dump($status_replies_); //no output on var_dump while ($row = $status_replies_) { echo "<pre>"; var_dump($row); echo "</pre>"; $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 id='".$status_reply_id."' class='replyboxes'><div><b>Reply by<a href='search_results.php?u=".$reply_author."'>".$reply_author."</a>".$reply_date ."<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' title='Edit this comment' >Edit</a></li>" . "<li><a href='report.php?u='".$reply_author."'>Report</a><li></ul>" . "</button></b></legend><br>".$reply_data."</div></div>"; } } while ($row1 = $status2view) { for ($j = 0; $j >= 0; $j++) { $updateid=$row1[$j]['update_id']; $account_name=$row1[$j]['account_name']; $os_id=$row1['os_id']; $author=$row1['author']; $post_date=$row1['time']; $title= htmlentities($row1['title']); $data= htmlentities($row1['update_body']); if ($row1==NULL) { break; } $status_list='<fieldset><div id="'.$updateid.'" class="statusboxes"><div>' . '<legend><h3 class="pull-left">'.$title.'</h3><span class="pull-right">'.$statusdeletebutton.'</span></legend><br>' . $data.'<br><b>Posted by<small><a href="search_results.php?u='.$author.'">'.$author.'</a>'.$post_date.'</small></b>' . '<br><hr style="2px dashed #080808">'.$status_replies . '</div></div>'.$statusui_edit.'</fieldset>'; here is the code for the method: public function statusView($session_uname,$f_uname) { $sql="select * from updates where account_name=:either and type='a' or account_name=:either and type='c' order by time desc limit 20"; $stmth=$this->_db->prepare($sql); $stmth->bindValue(":either",($session_uname|$f_uname)); $stmth->execute(); return $stmth->fetchAll(PDO::FETCH_ASSOC); } 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); }
  11. Hi all. I don't know why this is happening. I have a scrip that backs up database. It works fine on database1 but when i use it on database2, it throws an error? Fatal error: Call to a member function fetch_row() on a non-object in $tableshema = $shema->fetch_row() ; both databases are on same domain. ps: even with another backup script still throws an error in database2 thanks ##################### //CONFIGURATIONS ##################### // Define the name of the backup directory define('BACKUP_DIR', 'cashBackup' ) ; // Define Database Credentials define('HOST', 'localhost' ) ; define('USER', 'username' ) ; define('PASSWORD', 'password' ) ; define('DB_NAME', 'database2' ) ; /* Define the filename for the Archive If you plan to upload the file to Amazon's S3 service , use only lower-case letters . Watever follows the "&" character should be kept as is , it designates a timestamp , which will be used by the script . */ $archiveName = 'mysqlbackup--' . date('d-m-Y') . '@'.date('h.i.s').'&'.microtime(true) . '.sql' ; // Set execution time limit if(function_exists('max_execution_time')) { if( ini_get('max_execution_time') > 0 ) set_time_limit(0) ; } //END OF CONFIGURATIONS /* Create backupDir (if it's not yet created ) , with proper permissions . Create a ".htaccess" file to restrict web-access */ if (!file_exists(BACKUP_DIR)) mkdir(BACKUP_DIR , 0700) ; if (!is_writable(BACKUP_DIR)) chmod(BACKUP_DIR , 0700) ; // Create an ".htaccess" file , it will restrict direct access to the backup-directory . $content = 'deny from all' ; $file = new SplFileObject(BACKUP_DIR . '/.htaccess', "w") ; $written = $file->fwrite($content) ; // Verify that ".htaccess" is written , if not , die the script if($written <13) die("Could not create a \".htaccess\" file , Backup task canceled") ; // Check timestamp of the latest Archive . If older than 24Hour , Create a new Archive $lastArchive = getNameOfLastArchieve(BACKUP_DIR) ; $timestampOfLatestArchive = substr(ltrim((stristr($lastArchive , '&')) , '&') , 0 , - ; if (allowCreateNewArchive($timestampOfLatestArchive)) { // Create a new Archive createNewArchive($archiveName) ; } else { echo '<p>'.'Sorry the latest Backup is not older than 24Hours , try a few hours later' .'</p>' ; } ########################### // DEFINING THE FOUR FUNCTIONS // 1) createNewArchive : Creates an archive of a Mysql database // 2) getFileSizeUnit : gets an integer value and returns a proper Unit (Bytes , KB , MB) // 3) getNameOfLastArchieve : Scans the "BackupDir" and returns the name of last created Archive // 4) allowCreateNewArchive : Compares two timestamps (Yesterday , lastArchive) . Returns "TRUE" , If the latest Archive is onlder than 24Hours . ########################### // Function createNewArchive function createNewArchive($archiveName){ $mysqli = new mysqli(HOST , USER , PASSWORD , DB_NAME) ; if (mysqli_connect_errno()) { printf("Connect failed: %s", mysqli_connect_error()); exit(); } // Introduction information $return = "--\n"; $return .= "-- A Mysql Backup System \n"; $return .= "--\n"; $return .= '-- Export created: ' . date("Y/m/d") . ' on ' . date("h:i") . "\n\n\n"; $return .= "--\n"; $return .= "-- Database : " . DB_NAME . "\n"; $return .= "--\n"; $return .= "-- --------------------------------------------------\n"; $return .= "-- ---------------------------------------------------\n"; $return .= 'SET AUTOCOMMIT = 0 ;' ."\n" ; $return .= 'SET FOREIGN_KEY_CHECKS=0 ;' ."\n" ; $tables = array() ; // Exploring what tables this database has $result = $mysqli->query('SHOW TABLES' ) ; // Cycle through "$result" and put content into an array while ($row = $result->fetch_row()) { $tables[] = $row[0] ; } // Cycle through each table foreach($tables as $table) { // Get content of each table $result = $mysqli->query('SELECT * FROM '. $table) ; // Get number of fields (columns) of each table $num_fields = $mysqli->field_count ; // Add table information $return .= "--\n" ; $return .= '-- Tabel structure for table `' . $table . '`' . "\n" ; $return .= "--\n" ; $return.= 'DROP TABLE IF EXISTS `'.$table.'`;' . "\n" ; // Get the table-shema $shema = $mysqli->query('SHOW CREATE TABLE '.$table) ; // Extract table shema $tableshema = $shema->fetch_row() ; // Append table-shema into code $return.= $tableshema[1].";" . "\n\n" ; // Cycle through each table-row while($rowdata = $result->fetch_row()) { // Prepare code that will insert data into table $return .= 'INSERT INTO `'.$table .'` VALUES ( ' ; // Extract data of each row for($i=0; $i<$num_fields; $i++) { $return .= '"'.$rowdata[$i] . "\"," ; } // Let's remove the last comma $return = substr("$return", 0, -1) ; $return .= ");" ."\n" ; } $return .= "\n\n" ; } // Close the connection $mysqli->close() ; $return .= 'SET FOREIGN_KEY_CHECKS = 1 ; ' . "\n" ; $return .= 'COMMIT ; ' . "\n" ; $return .= 'SET AUTOCOMMIT = 1 ; ' . "\n" ; //$file = file_put_contents($archiveName , $return) ; $zip = new ZipArchive() ; $resOpen = $zip->open(BACKUP_DIR . '/' .$archiveName.".zip" , ZIPARCHIVE::CREATE) ; if( $resOpen ){ $zip->addFromString( $archiveName , "$return" ) ; } $zip->close() ; $fileSize = getFileSizeUnit(filesize(BACKUP_DIR . "/". $archiveName . '.zip')) ; $message = <<<msg <h4>BACKUP completed ,</h4> <p> The backup file has the name of : <strong> $archiveName </strong> and it's file-size is : $fileSize. </p> <p> This zip archive can't be accessed via a web browser , as it's stored into a protected directory.<br> It's highly recomended to transfer this backup to another filesystem , use your favorite FTP client to download the file . </p> msg; echo $message ; } // End of function creatNewArchive // Function to append proper Unit after a file-size . function getFileSizeUnit($file_size){ switch (true) { case ($file_size/1024 < 1) : return intval($file_size ) ." Bytes" ; break; case ($file_size/1024 >= 1 && $file_size/(1024*1024) < 1) : return round(($file_size/1024) , 2) ." KB" ; break; default: return round($file_size/(1024*1024) , 2) ." MB" ; } } // End of Function getFileSizeUnit // Funciton getNameOfLastArchieve function getNameOfLastArchieve($backupDir) { $allArchieves = array() ; $iterator = new DirectoryIterator($backupDir) ; foreach ($iterator as $fileInfo) { if (!$fileInfo->isDir() && $fileInfo->getExtension() === 'zip') { $allArchieves[] = $fileInfo->getFilename() ; } } return end($allArchieves) ; } // End of Function getNameOfLastArchieve // Function allowCreateNewArchive function allowCreateNewArchive($timestampOfLatestArchive , $timestamp = 24) { $yesterday = time() - $timestamp*3600 ; return ($yesterday >= $timestampOfLatestArchive) ? true : false ; } // End of Function allowCreateNewArchive
  12. I have been using the below method to access my database for some time now and just wanted to make sure im doing the correct thing. My application runs perfectly but im just trying to improve my programming skills. The classes are all loaded in with an autoloader so in theory using the classes below I could just call: echo User::getUsername(1); Like I say it works fine I would just love some feedback about what other people do and suggestions on something that might run better or looks cleaner. class Db { private static $db_read; private static $db_write; public static method read(){ if( self::$db_read == null ){ //create new database connection is it doesnt exist self::$db_read = new PDO(); } return self::$db_read; } public static method write() { if( self::$db_write == null ){ //create new database connection is it doesnt exist self::$db_write = new PDO(); } return self::$db_write; } class User { public static function getUsername($user_id){ $d = Db::read()->prepare('select * from user where id = ? '); $d->execute( array($user_id) ); $user = $d->fetch(); return $user['username']; } }
  13. hi, guys can any one say where im going wrong in this code as im not able to get to display friend lists in both search_results.php and home.php. the code in friend_list.php which is included in both home and search results page to display friends list: <?php $friends_html=""; $orlogic=""; $uname_s= \htmlentities($_GET['u']); $sql="select count(friend_id) from friends where friend_one=:uname_s and accepted='1' or friend_two=:uname_s and accepted='1'"; $stmt=$conn->prepare($sql); $stmt->bindparam(":uname_s", $uname_s); $stmt->execute(); $query_count=$stmt->fetchAll(PDO::FETCH_ASSOC); $friend_count=$query_count[0]; if ($friend_count<1) { $friends_html="$uname_s has no friends yet"; } else { $all_friends=array(); $sql="select friend_one, friend_two from friends where friend_two=:uname_s and accepted='1' order by rand()"; $stmt=$conn->prepare($sql); $stmt->bindparam(":uname_s",$uname_s); $stmt->execute(); while ($row =$stmt->fetchAll(PDO::FETCH_ASSOC)) { array_push($all_friends, $row[0]['friend_one']); } $sql1="select * from friends where friend_one=:uname_s and accepted='1' order by rand()"; $stmt1=$conn->prepare($sql1); $stmt1->bindparam(":uname_s",$uname_s); $stmt1->execute(); while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { array_push($all_friends, $row1['friend_two']); } $friendArrayCount= count($all_friends); foreach ($all_friends as $key => $user) { $orlogic .="uname='$user' OR"; } $orlogic1= chop($orlogic, "OR"); $sql2="select uname,avatar from user where :orlogic1"; $stmt2=$conn->prepare($sql2); $stmt2->bindparam(":orlogic1",$orlogic1); $stmt2->execute(); while ($row11 = $stmt2->fetchAll(PDO::FETCH_ASSOC)) { $friend_username=$row11[0]["uname"]; $friend_avatar=$row11[0]["avatar"]; if ($friend_avatar!=""){ $friend_pic='user/'.$friend_username.'/'.$friend_avatar; } else { $friend_pic='img/avatardefault.png'; } echo '<a href="search_results.php?u='.$friend_username.'"><img class="friendpics" src="'.$friend_pic.'" height="80" width="80" alt="'.$friend_username.'" title="'.$friend_username.'">'.$friend_username.'</a>'; } } if you guys need any further info please let me know
  14. Hi all. How can i send mail to multiple users at the same time with each user getting their own related data. I'm using php mailer as an engine to send the mail. Based on this, i'd have loved to setup a cron for it but i do not know how, so i figure i'd just do it manually before i get to know how to setup a cron job. It's just to send a reminder to users and each user has a different subscription expiry time. I want each user to get their respective expiration date, expiry day etc. Thanks if(isset($_POST['send_reminder'])){ $sql = "SELECT * FROM users WHERE status = '$status'"; $stmt = $pdo->query($sql); $stmt->execute(); while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ $name = $row['name']; $acct_no = $row['acct_no']; $email_addresses = $row['email']; $expiry_date = $row['expiry_date']; $expiry_day = $row['expiry_day']; } $message="Hello $name,<br> <p> This is to remind you that your subscription will expire in $expiry_day. </p> <p> Details as follows: Name: $name<br> Account Number: $acct_no<br> Email: $email_addresses<br> Expire in days: $expiry_day<br> Expiry Date: $expiry_date </p> <p> Thank you </p> $mail = new PHPMailer; //$mail->SMTPDebug = 3; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'mail.server.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'mails@services.cap'; // SMTP username $mail->Password = 'password'; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; // TCP port to connect to $mail->From = mails@services.cap'; $mail->FromName = 'Club 404'; $mail->addAddress($email_addresses); // Add a recipient $mail->WordWrap = 587; // Set word wrap to 50 characters $mail->AddEmbeddedImage("../img/logo.png", "my_logo"); $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'REMINDER ON CLUB EXPIRY DATE'; $mail->Body = $mess; $mail->send(); }
  15. I'm looking for an application or a social wall plugin to be added to a project. After looking at Wordpress and finally sifting through all the plugins (maybe all), I have come to a conclusion the plugins are not giving me enough customization options. For example, customizing the registration form. I need to add javascript for a combo box in order to display different options depending on what was selected. What I need - Your Opinion on a good social wall that's easy to make changes. I need a secure login and password --- PDO based A control panel would be nice to activate users or deactivate. A customized registration form Ability to add more pages, add php to customize it to work like I need it to. Responsive. If anyone has an opinion with experience on this matter it would be great to hear from you.
  16. I am trying to control the items shown by selecting them by active = 0. I can get it to work. Any help would be appreciated. <?php try { $sql = "SELECT company.co_name, company.active, co_info.customer_no, co_info.password, co_address, co_city, co_state, co_zip, host, ftp_name, ftp_password FROM company LEFT JOIN co_info ON company.id = co_info.id WHERE company.active = '0' "; $result = $dbh->query($sql);
  17. Hi all. I generated a random number and assigned it a variable to be used through out the session but on getting to the next page, the value changes. It is regenerating another number which isnt the intention. I have tried severally but no way! i really cannot figure out why the value changes in my second page. $loan = mt_rand(1000, 9999); $name = "John"; if(isset($_POST['continue'])){ $_SESSION['num'] = $number; $sql = ("INSERT INTO table (name, token_number) VALUES(:name, :token_number) $stmt=$pdo->prepare($sql); $stmt->execute(array( ':name'=>$name; ':token_number'=>$_SESSION['num'] )); if($stmt->rowCount()==1){ header("location: nextpage.php"); }else{ echo "Something went wrong"; } }
  18. I am trying to coonect my jquery price slider to my database in order to search for recipes depending on the price. I have written the code below but I am not sure were i am going wrong. Could anyone help? <!--Javascript code for jquery price range slider--> <script type="text/javascript"> $(function() { $( "#slider-range" ).slider({ range: true, min: 0, max: 10, values: [ <?php echo $min?>,<?php echo $max?> ], // This line could be the issue? slide: function( event, ui ) { $( "#amount" ).val( "£" + ui.values[ 0 ] + " - £" + ui.values[ 1 ] ); } }); $( "#amount" ).val( "£" + $( "#slider-range" ).slider( "values", 0 ) + " - £" + $( "#slider-range" ).slider( "values", 1 ) ); }); </script> <!--php code to connect to jquery price slider--> <?php require_once './config.php'; include './header.php'; include('database.php'); if($_POST && isset($_POST['amount'])){ $values = $_POST['amount']; $values = str_replace(array(' ', '£'), '', $_POST['amount']); list($min, $max) = explode('-', $values); $sql = "SELECT `recipe_name`, `recipe_price`, `Image` FROM `recipe` WHERE `recipe_price` BETWEEN :min AND :max"; $stmt = $DB->prepare($sql); $stmt->execute(array(':min' => $min, ':max' => $max)); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); if (count($rows) > 0) { foreach ($rows as $row) { // do loop stuff } } else { $min = 0; $max = 10; $HTML = ''; } } ?> <!--HTML code for price slider --> <form action="" method="post" id="recipe"> <div style="margin-left:20px"> <label for="amount">Price range:</label> <input type="text" id="amount" name="amount" style="border:0; color:#f6931f; font-weight:bold;" readonly> <br><br> <div id="slider-range" style="width:50%;"></div> <br><br> <input type="submit" value="Find" /> <br><br> <?php echo $HTML?> </div> </form> <!-- connnect to Database - PDO connection--> <?php error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE); ob_start(); define('DB_DRIVER', 'mysql'); define('DB_SERVER', 'localhost'); define('DB_SERVER_USERNAME', 'xxxxx'); define('DB_SERVER_PASSWORD', 'xxxx'); define('DB_DATABASE', 'xxxxx'); define('PROJECT_NAME', 'BudGet Recipes'); $dboptions = array( PDO::ATTR_PERSISTENT => FALSE, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', ); try { $DB = new PDO(DB_DRIVER . ':host=' . DB_SERVER . ';dbname=' . DB_DATABASE, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, $dboptions); } catch (Exception $ex) { echo $ex->getMessage(); die; } ?>
  19. I cannot view data based upon my "wid" in the following code. Basically I have a page that you click on a link, and it passes a number to the "wid" as an integer. I want to call on that corresponding table that has a "like" wid. Here is what I have so far... <?php require 'database.php'; if(!empty($_GET['wid'])) { $wid = $_GET['wid']; } else { $wid = null; } if ( null==$wid ) { header("Location: workorders.php"); } else { $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = 'SELECT * FROM items where wid = ?'; $rows = $pdo->query($sql); foreach ($pdo->query($sql) as $row) { echo '<tr>'; echo '<td>'. $row['id'] . '</td>'; echo '<td>'. $row['wid'] . '</td>'; echo '<td>'. $row['model'] . '</td>'; echo '<td>'. $row['description'] . '</td>'; echo '<td>'. $row['cost'] . '</td>'; echo '<td>'. $row['retail'] . '</td>'; echo '<td>'. $row['tax'] . '</td>'; echo '<td width=250>'; } Database::disconnect(); } ?>
  20. Here's my example of using transactions in PDO: I am getting the two errors below when I run my scripts in the browser. PDOException: There is no active transaction in...... Fatal error: Uncaught exception 'PDOException' with message 'There is no active transaction' in ...... here is ny pdo database connection class: <?php class conn { public $host = ''; public $dbname = ''; public $username = ''; public $password = ''; /** * @var object $db_connection The database connection */ private $db_connection = null; public function __construct($host, $dbname, $username, $password) { $this->host = $host; $this->dbname = $dbname; $this->username = $username; $this->password = $password; } public function connected() { try { $this->db_connection = @new PDO('mysql:host='.$this->hos.';dbname='.$this->dbname.';charset=utf8mb4', $this->username, $this->password); return $this->db_connection; } catch (PDOException $e) { echo "Unable to connect to the PDO database: " . $e->getMessage(); } } } And below is the database queries: <?php require('config/conn.php'); $host = 'localhost'; $dbname = 'dbname'; $username = 'username'; $password = 'password'; $db = new conn($host, $dbname, $username, $password); try { //note that calling beginTransaction() turns off auto commit automatically $db->connected()->beginTransaction(); $stmt = $db->connected()->prepare("INSERT INTO category_types (name, cat_id) VALUES (:name, :value)"); $stmt->bindParam(':name', $name); $stmt->bindParam(':value', $value); // insert one row $name = 'one'; $value = 1; $stmt->execute(); // insert another row with different values $name = 'two'; $value = 2; $stmt->execute(); $stmt = $db->connected()->prepare("INSERT INTO category_types2 (name, cat_id) VALUES (:name, :value)"); $stmt->bindParam(':name', $name); $stmt->bindParam(':value', $value); // insert one row $name = 'one'; $value = 1; if($stmt->execute()) //all went well commit! $db->connected()->commit(); } catch (Exception $e) { //Something went wrong rollback! $db->connected()->rollBack(); echo "Failed: " . $e->getMessage(); } What might I be doing wrong? Thanks
  21. Hi I’m looking for a standalone PHP OOP framework or code that follows best practices using - PDO prepared statements - Singleton Design Pattern Not looking for a massive library, something short and sweat straight to the point Any comments, feedback would be appreciated
  22. Hi all. I have two tables where the username is what they have in common. i want to perform a join for both tables but i'm having problems with mysql joins. //to get the desire result individually i did //table one $stmt = $pdo->query("SELECT * FROM tableone WHERE username = '$_GET[id]'"); $row = $stmt->fetch(PDO::FETCH_ASSOC); $credit_score = $row['credit_score']; $acct_num = $row['acct_num']; $acct_name = ucwords($row['surname']) ." ". ucwords($row['firstname']); $username = $row['username']; if($credit_score ==3){ $bill_limits = 2000; }elseif($credit_score ==2){ $bill_limits = 1000; }elseif($credit_score ==1){ $bill_limits = 500; } //table two $stmt=$pdo->query("SELECT SUM(amt) as bill FROM tabletwo WHERE username = '$_GET[id]' AND relationship = 'PARENT'"); $row = $stmt->fetch(PDO::FETCH_ASSOC); $bill = $row['bill']; $service_charge_for_limits = '0.05' * $bill; $tax_rate_for_limits = '0.13' * $service_charge_for_limits; $bill_sum = $tax_rate_for_limits + $service_charge_for_limits + $bill; Approved Bill Limits = $<?php echo number_format($bill_limits,2); ?> <br> Bill Limits Used = $<?php echo number_format($bill_sum,2); ?> <br> <?php $available_limits = $bill_limits - $bill_sum; ?> Bill Limits Available = $<?php echo number_format($available_limits,2); ?> The above gives me the correct result, but now i have another page where i want to all the clients and their corresponding available limits, used limits and approve limits form table two and other information from table one On the page i have $stmt = $pdo->prepare("SELECT * FROM tableone WHERE status = 'COMPLETED' ORDER BY id DESC LIMIT $start, $limit"); $stmt->execute(); $num_rows = $stmt->rowCount(); echo "<table width='100%' class='table-responsive table-hover table-condensed table-striped'>"; echo "<tr> <th bgcolor='#444444' align='center'><font color='#fff'>Account Number</th> <th bgcolor='#444444' align='center'><font color='#fff'>Subscriber's Name</font></th> <th bgcolor='#444444' align='center'><font color='#fff'>Username</font></th> <th bgcolor='#444444' align='center'><font color='#fff'>Limits ($)</font></th> <th bgcolor='#444444' align='center'><font color='#fff'>View Profile</font></th> <th bgcolor='#444444' align='center'><font color='#fff'>Delete Account</font></th> </tr>"; // keeps getting the next row until there are no more to get while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['acct_num']; echo "</td><td>"; echo ucwords($row['surname']." ". $row['firstname']); echo "</td><td>"; echo $row['username']; echo "</td><td>"; $credit_score = $row['credit_score']; if($credit_score ==3){ $bill_limits = 2000; }elseif($credit_score ==2){ $bill_limits = 1000; }elseif($credit_score ==1){ $bill_limits = 500; } echo number_format($bill_limits, 2); echo "</td><td>"; echo "<a href='view-client-profile.php?id={$row['username']}'>view more</a>"; echo "</td><td>"; echo "<a href='delete-account.php?id={$row['username']}'>Delete Account</a>"; echo "</td></tr>"; //echo "</td><td>"; //echo "<a href='settle.php?id={$row['acct_num']}'>Points</a>"; } echo "</table>"; How ca i join tableone and tabletwo (plus sum)
  23. Hello all. I am trying to get values from two tables but i am getting the wrong output regardless of the type of join i use. The two query have some similar columns/rows. I want to fetch only the specified columns/rows with their unique data but my query is giving me on a column the value of just another column. For instance if a description column in table A has a value of INVOICE and on table B the description is RECEIPT all my query show is either INVOICE or RECEIPT in all the columns regardless of whether the description is receipt or not and also i want all the fields that is not on the other table to be blank and not replicate columns eg. description. image refuse to show when attached and wouldn't allow me to use the image link on the editor, said i am not allowed. SELECT table1.trans_ref, table1.description, table1.date_paid, table1.recurring, table1.amt, table1.bill_code, table2.trans_ref, table2.description, table2.amt_deposited, table2.deposit_date FROM table1 RIGHT JOIN table2 ON table1.username = table2.username ps: would want amount and deposit amount to be on same column and also use a where username = username. or maybe i am not doing the right thing? is it possible to a select on two tables without using a JOIN? so that you can echo only the needed values in a loop. thanks
  24. So I have this code: <?php $user = "clicrckc_osherdo"; $pass = "3563077"; $CurrentUser= $_SESSION['user_id']; try { $dbh = new PDO('mysql:host=localhost;dbname=clicrckc_andfit', $user, $pass); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "connected successfully"; print_r($_SESSION); $UserName = $dbh->prepare("SELECT first_name,last_name FROM users WHERE user_id = ?"); $UserName->bindParam(1, $CurrentUser); $UserName->execute(); $UserName->fetch(PDO::FETCH_ASSOC); $dbh = null; } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; die(); } ?> <div id="PersonalDetails">Hello dear <?= $UserName ?>!</div> I am trying to insert the current username in the session to the html code where $Username is. I cannot find out why it wont work. I am getting the following message, instead of the current username in the session: Catchable fatal error: Object of class PDOStatement could not be converted to string in/home/clicrckc/public_html/dashboard.phpon line136 I have tried to google the issue but I could not address the issue. please- help anyone? Thank you.
  25. hi I want to use url attachments for other post instead upload files again. Duplicate row(s) of attachments table with "attid field" posted from form and change a "postid field" in same table. I have a form with some input checkbox. The values of input are numbers which point to values of the field in database (attachments table > attid field ). <input type="checkbox" name="attid[]" value="10" /> <input type="checkbox" name="attid[]" value="250" /> This "attid" field is a Primary Key and AUTO_INCREMENT. I want when form submit, duplicate a row(s) with "attid" posted. Used this > INSERT INRO - SELECT query with loop by for each but not succesful $sql = ('INSERT INTO attachments (field1, field2) (SELECT * FROM attachments WHERE attid= :attid)'); thanks
×
×
  • 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.