Jump to content

shan

Members
  • Posts

    57
  • Joined

  • Last visited

Posts posted by shan

  1. 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);
     
            }
    
  2. an update, i changed a few code in login.inc.php and found that if i use isset in var_dump on "$user" it outputs bool(true). Since i was not able to understand the abstract available on the net i was wondering what u guys has to say about it.

    here is the updated code for login php page:

    echo'<pre>';
    var_dump(empty( $user));
    print_r(isset($user));
    echo'</pre>';
    exit();
    

    here is the output:

    bool(true)
    1
    
  3. here is the code for index page where there is form:

    <?php
    if (@$_GET['id']==017) {
        echo '<script>alert("User Not Found, Please enter Proper Credentials");</script>';
    }
    ?>
    
    <!DOCTYPE html>
    
    <html>
        <head>
            <meta charset="UTF-8">
            <title>Sign in or Sign up!</title>
            <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
            <link href="css/custom.css" rel="stylesheet" type="text/css"/>
            <script src="js/respond.js" type="text/javascript"></script>
            <script type="text/javascript" src="js/jquery-1.11.3.min.js" type="text/javascript"></script>
            <script src="js/bootstrap.min.js" type="text/javascript"></script>
            <script src="js/custom.js" type="text/javascript"></script>
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
     
        </head>
        <body>
            <div class="row"><header class="header-custom visible-phone visible-tablet visible-desktop">
                    <div class="head-col-left-custom hidden-xs ">LOGO!</div>
                    <div class="head-col-middle-custom">
                        <form action="includes/login.inc.php" method="post">
                            <tr><td>Username: <input type="text" required placeholder="Username" class="input-custom input-group-sm input-sm" name="unamel"> </td></tr>
                            <tr><td>Password:<input class="input-custom input-group-sm  input-sm" type="password" name="passl" required placeholder="Password">  
                                    <input type="submit" name="submit-login" value="login" class="btn btn-warning btn-danger-custom"> | </p> <a href="forgotpass.php">?Forgot Password</a></td></tr>
                        </form>
                    </div>
                </header>
            </div>
            <br>
        
      
    <div class="row row-md-custom"><div class="col-xs-offset-1"></div><div class="col-xs-6"><div class="jumbotron jumbotron-position thumbnail"><h2>About US</h2><p>Proin faucibus arcu quis ante. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero.
    
    Ut leo. Vivamus euismod mauris.</p></div></div>
        <div class="col-xs-1"></div><div class="col-xs-5"><h2>Register here!</h2><form action="includes/register.inc.php"  method="post"><table> 
                                            <tr><td><input type="text" name="fnamer" placeholder="Firstname"required="please enter your first name" class="input-custom input-group-lg input-group-sm input-lg input-sm"></td></tr>
                                            <tr><td><input type="text" name="lnamer" placeholder="Lastname"required="" class="input-custom input-group-lg input-group-sm input-lg input-sm"></td></tr>
                                            <tr><td><input type="text" name="unamer" placeholder="Username" required="" class="input-custom input-group-lg input-group-sm input-lg input-sm uname-val"></td>
                                            <td><p class="js-write_u_r"></p></td></tr>
                                            <tr><td><input type="password" name="passr" placeholder="Password"required="" id="pass0"class="input-custom input-group-lg input-group-sm input-lg input-sm pass0"></td></tr>
                                            <div> </div><tr><td><input type="password" name="pass1r" placeholder="Retype Password" required=""id="pass1" class="input-custom input-group-lg input-group-sm input-lg input-sm pass1" ></td>
                    <td><p class="js-write"></p></td></td></tr>
                                            <br><tr><td><input type="email" name="emailr" placeholder="email" required="" class="uname-e-val input-custom input-group-lg input-group-sm input-lg input-sm"></td> <td><p class="js-write_e_r"></p></td></tr>
                                            <br><tr><td><input type="text" name="phoner" placeholder="Phone Number" required="" class="input-custom input-group-lg input-group-sm input-lg input-sm phone-val"></td> <td><p class="js-write_p_r"></p></td></tr>
                <br><tr><td><br><button type="submit" name="submit-register" value="login"  class="btn btn-group-lg btn-danger btn-lg">Register</button></td></tr>
            </table></form></div><br><div> </div>
    
    <?php include 'includes/footer.php';?>
    </body>
    </html>
    
    

    the login page logic:

    <?php   
    include_once 'dbconfig.inc.php';
    if (isset($_POST['submit-login'])) {
    $uname= htmlspecialchars($_POST['unamel']);
    $unamel=  stripslashes($_POST['unamel']);
    $pass= htmlspecialchars($_POST['passl']);
    $pass1= stripslashes($_POST['passl']);
    $passl=  md5($pass1);
    $user = $project->viewProtectedArea($unamel,$passl);
    var_dump($_POST);                 
    var_dump($user);
    exit();
        if ($user) {
        
                     $_SESSION['id']=$user['user_id'];
                      $_SESSION['fname']=$user['fname'];
                       $_SESSION['lname']=$user['lname'];
                      $_SESSION['uname']=$user['uname'];
                      $_SESSION['email']=$user['email'];
                      $_SESSION['phone']=$user['phone'];
                      $_SESSION['app']=TRUE;
                      $user_ok=TRUE;
                       header("location: ../home.php?u={$_SESSION['uname']}");
    
                      
        }  else {
            header("location: ../index.php?nosession");
        }
    
    
    
    
    
    }    
    /*
    if (isset($_SESSION['app'])&&$_SESSION['uname']!="") {
        echo 'your name is '.$_SESSION['fname'];                        
                      } else {
                          header("location: ../index.php?usernotfound?id=017");
                      }
      */
    
    

    and the code for register page is as follows:

    <?php
    
    require 'dbconfig.inc.php';
    if (isset ($_POST['submit-register'])) {
       $fname= htmlentities($_POST['fnamer']);
       $lname= htmlentities($_POST['lnamer']);
       $uname1= htmlentities($_POST['unamer']);
       $pass1=  htmlentities($_POST['passr']);
       $pass0= md5($pass1);
       //include 'randString.php';
       $p_hash=  $pass0;
       $email=  htmlentities($_POST['emailr']);
       $phone=  htmlentities($_POST['phoner']);
       $fnamer=  stripslashes($fname);
       $lnamer= stripslashes($lname);
       $unamer=  stripslashes($uname1);
       $passr=  stripslashes($p_hash);
       $emailr= stripslashes($email);
       $phoner=  stripslashes($phone);
       $activate=0;
           $create=$project->createUser($fnamer,$lnamer,$unamer,$passr,$emailr,$phoner,$activate);
           $user1=$project->viewProtectedArea($unamer,$passr);
       $uname= "../user/{$unamer}";
                      if (!file_exists("$uname")) {
                          exec("`mkdir $uname`");
                          
                      }
                       $sql="insert into useroptions (uname_options, background) values (:uname,'original')";
                       $stmth=$conn->prepare($sql);
                       $stmth->bindparam(":uname", $unamer);
                      // $stmth->bindparam(":org", 'original');
                       $stmth->execute();
                    $e=$emailr;
                    $from="gsshanker10@gmail.com";
                    $subject="Account Activation";
                    $message='<!DOCTYPE html>
    
    <html>
        <head>
            <meta charset="UTF-8">
            <title>Protected Area.</title>
            <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
            <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
       <meta name="viewport" content="width=device-width, initial-scale=1.0">
        </head>
        <body>
            <div class="row">
                <header class="header-custom visible-phone visible-tablet visible-desktop" style="background: red; box-shadow: 5px;">
                    <div class="head-col-left-custom ">LOGO!</div>
                    <div class="head-col-middle-custom pull-right ">
    <h1>Please Activate youtr account!</h1>   
    </div>
                    </div>
                              </header>
                          </div>
                          <br>
                    <h2>Please Activate your Account!</h2><br>
                    <div> </div>
                    <div>Please Click here to <a href="http://localhost/activation.php?id='.$user1["user_id"].'&e='.$user1["email"].'&u='.$user1["uname"].'&p='.$p_hash.'">activate your Account</a>
         <br>
         <p>Or copy and paste the below link to activate </p><br>
         <p>http://localhost/project/activation.php?e='.$emailr.'&u='.$unamer.'&p='.$p_hash.'</p>
    </div>   
    </body></html>
    
    ';   
       $headers="from:$from \n";
       $headers="MIME-version:1.0\n";
       $headers="content-type:text/html;charset=is0-8859-1\n";
                    
    require '../PHPMailer/class.phpmailer.php';
    $mail = new PHPMailer;
     
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'gsshanker10@gmail.com';
    $mail->Password = 'wtfuslydevil@143';
    $mail->SMTPSecure = 'tls';
     $mail->Port = 587;
    $mail->From = $from;
    $mail->FromName = 'Gowri';
    $mail->addAddress($e, 'gowri');
     
    $mail->addReplyTo('gsshanker10@gmail.com', 'gowri shanker');
     
    $mail->WordWrap = 50;
    $mail->isHTML(true);
     
    $mail->Subject = $subject;
    $mail->Body    = $message;
     
    if(!$mail->send()) {
       echo 'Message could not be sent troubleshoot.';
       echo 'Mailer Error: ' . $mail->ErrorInfo;
       exit();
    }
     
    echo 'Message has been sent';
    
                      
          
    }                           
      if (isset($_SESSION)) {
        header("location: ../home.php?id={$_SESSION["uname"]}");
        
        }  else {
        header("location: ../index.php");    
    }
        
     
          
             
       
    
     
    

    here is the code for custom.js:

    var $ =jQuery.noConflict();
    $(document).ready(function (){
    var spinner="<img src='img/spinner.gif'>";   
    $(".pass1").focusout(function(){
        $(spinner).show();
      var p0 =  $(".pass0").val();
      var p1 = $(this).val();
      if(p1===""){
            $(".js-write").html('<span class="glyphicon glyphicon-remove" style="color: red;"> Please re-enter your Password.</span>');
       $(spinner).hide();
        }
        else if(p0===p1){
           $(".js-write").html('<span class="glyphicon glyphicon-ok"style="color: red;"> Passwords Match.</span>');
       $(spinner).hide();
            return true;
            
        }
      
      else
      {
        
       $(".js-write").html('<span class="glyphicon glyphicon-remove"style="color: red;"> Passwords Dont Match.</span>');
    $(this).focus();
    return false; 
     $(spinner).hide();
        }
    });
    
    $(".js-write_e_r").html('<span class="glyphicon glyphicon-arrow-left"style="color: red;">Important Field</span>');
    $(".js-write_p_r").html('<span class="glyphicon glyphicon-arrow-left"style="color: red;">Important Field</span>');
    $(".js-write_u_r").html('<span class="glyphicon glyphicon-arrow-left"style="color: red;">Important Field</span>');              
    $(".uname-val").focusout(function(){
        var uname_val=$(".uname-val").val();
        //displays a loader while it is checking the database
            if(uname_val=="") {
                    $(".js-write_u_r").html('<span class="glyphicon glyphicon-remove"style="color: red;"> Username is not Available or invalid.</span>');
    
            }       
                            
    //here is where you send the desired data to the PHP file using ajax
            $.post("includes/uname_val.php", {unamer:uname_val},
                function(result) {
                    
                    if(result ==1) {
                        //the uname is available
                    $(".js-write_u_r").html('<span class="glyphicon glyphicon-ok"style="color: red;"> Username Is Available</span>');
                  
                    }
                    else if(result==0) {
                        //the uname is not available
                        $(".js-write_u_r").html('<span class="glyphicon glyphicon-remove"style="color: red;"> Username is not Available or already taken.</span>');
                                }
                    
                    
                    
                    
    });
    });
    $(".uname-e-val").focusout(function(){
        var email_val=$(".uname-e-val").val();
        //displays a loader while it is checking the database
            
                            
    //here is where you send the desired data to the PHP file using ajax
            $.post("includes/uname_e_val.php", {emailr:email_val},
                function(result) {
                    
                    if(result ==1) {
                        //the uname is available
                    $(".js-write_e_r").html('<span class="glyphicon glyphicon-ok"style="color: red;"> E-mail not in use</span>');
                  
                    }
                    else if(result==0) {
                        //the uname is not available
                        $(".js-write_e_r").html('<span class="glyphicon glyphicon-remove"style="color: red;"> E-mail is already registered or not entered.</span>');
                                }
                    
                    
                    
                    
    });
    });
    $(".phone-val").focusout(function(){
        var phone_val=$(".phone-val").val();
        //displays a loader while it is checking the database
            
                            
    //here is where you send the desired data to the PHP file using ajax
            $.post("includes/uname_p_val.php", {phoner:phone_val},
                function(result) {
                    
                    if(result ==1) {
                        //the uname is available
                    $(".js-write_p_r").html('<span class="glyphicon glyphicon-ok"style="color: red;"> Phone not in Use </span>');
                  
                    }
                    else if(result==0) {
                        //the uname is not available
                        $(".js-write_p_r").html('<span class="glyphicon glyphicon-remove"style="color: red;">Phone no is already registered or not entered.</span>');
                                }
                    
                    
                    
                    
    });
    });
    
    
    

    if u need anything else please let me know.@mac_gyver

  4. @mac gyver

    here is the html form code:

     <div class="row"><header class="header-custom visible-phone visible-tablet visible-desktop">
                    <div class="head-col-left-custom hidden-xs ">LOGO!</div>
                    <div class="head-col-middle-custom">
                        <form action="includes/login.inc.php" method="post">
                            <tr><td>Username: <input type="text" required placeholder="Username" class="input-custom input-group-sm input-sm" name="unamel"> </td></tr>
                            <tr><td>Password:<input class="input-custom input-group-sm  input-sm" type="password" name="passl" required placeholder="Password">  
                                    <input type="submit" name="submit-login" value="login" class="btn btn-warning btn-danger-custom"> | </p> <a href="forgotpass.php">?Forgot Password</a></td></tr>
                        </form>
                    </div>
                </header>
            </div>

    the var_dump for $_post seems to be fine. here is what it outputted in firefox(the user does exist in the DB):

    array(3) { ["unamel"]=> string(6) "qwerty" ["passl"]=> string(9) "gssh93986" ["submit-login"]=> string(5) "login" }
  5. hi, guys im actually trying to figure what is wrong here in my code as it var dumps in google chrome but not in firefox or opera, its quite confusing as php is a server side scripting language but is behaving like a client side script. it outputs fine in chrome but not in firefox as it gives "bool(false)" for the same script. can any one help me on this.

    the code to dbconfig is here:

    <?php
    session_start();
    $host="localhost";
    $dbName="project";
    $dbUname="root";
    $dbPass="";
    
    try
    {
    $conn=new PDO("mysql: host=$host;dbname=$dbName;charset=utf8", $dbUname, $dbPass);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    }
    catch (PDOException $e)
    {
        $e->getMessage();
    }
    require_once 'classes.inc.php';
    
    $project= new projecteg($conn);
    
    
    

    the code to class's method is here:

    public function viewProtectedArea($uname,$pass)
                    {
                       $active=1;
                       $stmth= $this->_db->prepare("select * from user where uname=:uname and pass=:pass and activated={$active}");
                       $stmth->bindparam(":uname",$uname);
                       $stmth->bindparam(":pass",$pass);
                       $stmth->execute();
                      return $stmth->fetch(PDO::FETCH_ASSOC);
                   
               }

    and the code to login page is here:

    include_once 'dbconfig.inc.php';
    if (isset($_POST['submit-login'])) {
    $uname= htmlentities($_POST['unamel']);
    $unamel= stripslashes($uname);
    $pass= htmlentities($_POST['passl']);
    $pass1= stripslashes($pass);
    $passl=  md5($pass1);
    $user = $project->viewProtectedArea($unamel,$passl);
                     
    var_dump($user);
    exit();
        if ($user) {
        
                     $_SESSION['id']=$user['user_id'];
                      $_SESSION['fname']=$user['fname'];
                       $_SESSION['lname']=$user['lname'];
                      $_SESSION['uname']=$user['uname'];
                      $_SESSION['email']=$user['email'];
                      $_SESSION['phone']=$user['phone'];
                      $_SESSION['app']=TRUE;
                      $user_ok=TRUE;
                       header("location: ../home.php?u={$_SESSION['uname']}");
    
                      
        }  else {
            header("location: ../index.php?nosession");
        }
    
    
    
    
    
    }   

    please help me out.

     

  6.  

    <?php
    
    $host="localhost";
    $dbName="project";
    $dbUname="root";
    $dbPass="";
    
    try
    {
    $conn=new PDO("mysql: host=$host;dbname=$dbName; charset=utf8", $dbUname, $dbPass);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    }
    catch (PDOException $e)
    {
     $e->getMessage(); //line 18
    }
    require_once 'classes.inc.php';
    
    $project= new projecteg($conn);
    
    
    

    as asked im posting you the code

  7. recently i changed my password for my mysql DB and after that the class method for the login form seems to be not working pl help me. And it doesn't throw up any errors too.

    the code in dbconfig.inc.php where the class is initiated is as follows:

     
     
    <?php
    session_start();
    $host="localhost";
    $dbName="project";
    $dbUname="root";
    $dbPass="*****";
    
    
    try
    {
    $conn=new PDO("mysql: host=$host;dbname=$dbName; charset=utf8", $dbUname, $dbPass);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    
    }
    catch (PDOException $e)
    {
        $e->getMessage();
    }
    require_once 'classes.inc.php';
    
    
    $project= new projecteg($conn);
    
    
    

    the login logic script page is as follows:(i tried to var_dump user its not working)

     

    <?php
               
    
    
    include_once 'dbconfig.inc.php';
    if (isset($_POST['submit-login'])) {
    $uname= htmlentities($_POST['unamel']);
    $unamel= stripslashes($uname);
    echo "$unamel";
    $pass= htmlentities($_POST['passl']);
    $pass1= stripslashes($pass);
    echo $pass1;
    $passl=  md5($pass1);
    $user = $project->viewProtectedArea($unamel,$passl);
    print_r($user);
        if (isset($user)) {
           
                     $_SESSION['id']=$user['user_id'];
                      $_SESSION['fname']=$user['fname'];
                       $_SESSION['lname']=$user['lname'];
                      $_SESSION['uname']=$user['uname'];
                      $_SESSION['email']=$user['email'];
                      $_SESSION['phone']=$user['phone'];
                      $_SESSION['app']=TRUE;
                      $user_ok=TRUE;
                       header("location: ../home.php?u={$_SESSION['uname']}"); 
    
    
                      
        }  else {
            header("location: ../index.php?nosession");
        }
    
    
    
    
    
    
    
    
    
    
    } 
    /*
    if (isset($_SESSION['app'])&&$_SESSION['uname']!="") {
       header("location: ../home.php?u=".$_SESSION['uname']);                       
                      } else {
                          header("location: ../index.php?usernotfound?id=017");
                      }
      */ 
    

    the class method logic is as follows:

     

    public function viewProtectedArea($unamel,$passl) 
                    {
                   try
                   {
                       $active='1';
                       $stmth= $this->_db->prepare("select * from user where uname=:uname and pass=:pass and activated={$active}");
                       $stmth->bindparam(":uname",$unamel);
                       $stmth->bindparam(":pass",$passl);
                       $stmth->execute();
                      return $stmth->fetch(PDO::FETCH_ASSOC);
                     
                      }
                      
                   
                   catch (PDOException $exc)
                   {
                       $exc->getMessage();
                       return false;
                   
                   }
                   
               }
  8. i'm sorry if i wasn't precise the error occurs in search_results.php page if the user views some profile who is not a friend and has not activated the account through email.

    i have tried to query->stmt and load info, it appears fine when viewing a accepted friendship but if we look at a person who is not a friend i get the following error.

    changed query now looks like this.

     
    $sql1="select * from friends where friend_one=:uname_s 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->query($sql2);
       //$stmt2->bindparam(":orlogic1",$orlogic1);
        //s$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="50" width="50" alt="'.$friend_username.'" title="'.$friend_username.'">'.$friend_username.'</a>';
    
    
        }
        
        
     }

    error msg that i get now is as follows:

     

    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1' in /opt/lampp/htdocs/project/notification/friend_list.php:42 Stack trace: #0 /opt/lampp/htdocs/project/notification/friend_list.php(42): PDO->query('select uname,av...') #1 /opt/lampp/htdocs/project/search_results.php(78): include_once('/opt/lampp/htdo...') #2 {main} thrown in /opt/lampp/htdocs/project/notification/friend_list.php on line 42

     

     

    thanks for the replies.

  9. @ch0cu3r the error message is as follows when running the code as follows in home.php:

    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORuname='shan2batman1'' at line 1' in /opt/lampp/htdocs/project/notification/friend_list.php:44 Stack trace: #0 /opt/lampp/htdocs/project/notification/friend_list.php(44): PDOStatement->execute() #1 /opt/lampp/htdocs/project/home.php(72): include_once('/opt/lampp/htdo...') #2 {main} thrown in /opt/lampp/htdocs/project/notification/friend_list.php on line 44

     

    the changed code looks like this:

    $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>';
    
    
        }
        
        
     }
  10. 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 :)

     

     

  11. thanks for the reply@ch0cu3r  :happy-04:

    now im facing a new problem its just that the file is now inserting ":session" and ":f_uname" instead of values in the database. since this is the first time im facing this problem im perplexed where to start debugging, can you help me on this??.

    i'll attach a screen shot of phpmyadmin  for clarifications.12046758_1135617329800809_25274618424023

     

    see the 7th id its storing like this.

  12. hi, guys im learning to create a friend and block system in php with jquery, but it gives the following error in firebug console in google chrome,

    "POST function (){ "parser/friend_sys.php", ({"user":user_f}), function(data){ if(data==1){ $(".block_btn").show(); $(".unfriend_btn").show(); }else{ } } }
    404 Not Found "

    i checked the file permissions(im using ubuntu 14.04), everything seems to be fine. but since im learning php and ajax i'm stumped can anyone help me out, my php and ajax code is as follows.

    <?php
    include 'includes/header.php';
    error_reporting(0);
    $sess_uname=  htmlentities($_SESSION['uname']);
    $session_uname=  stripslashes($sess_uname);
    $f_uname0=  htmlentities($_GET['name']);
    $f_uname= stripslashes($f_uname0);
    try {
        
    
    
    
    
    if ($f_uname!=$session_uname) {
        $freind_check="select friend_id from friends where friend_one=':session' and friend_two=':f_name' and accepted='1' limit 1";
        $stmt=$conn->prepare($freind_check);
        $stmt->bindparam(":session",$session_uname);
        $stmt->bindparam(":f_name",$f_uname);
        $stmt->execute();
      
       if ($stmt->fetchColumn()>0) {
         
           $is_friend=TRUE;
       }
       $blockcheck0="select blocked_id from blockedusers where blocker=':f_name' and blockee=':session' limit 1";
       $stmt1=$conn->prepare($blockcheck0);
        $stmt1->bindparam(":session",$session_uname);
        $stmt1->bindparam(":f_name",$f_uname);
        $stmt1->execute();
      
       if($stmt1->fetchColumn()>0)
       {
         $ownerblockviewer=TRUE;
       }
       $blockcheck2="select blocked_id from blockedusers whereblocker=':session' and blockee=':f_uname' limit 1";
        $stmt2=$conn->prepare($blockcheck0);
        $stmt2->bindparam(":session",$session_uname);
        $stmt2->bindparam(":f_name",$f_uname);
        $stmt2->execute();
      
       if($stmt2->fetchColumn()>0)
       {
         $viewerblockowner=TRUE;
       }
    }
    
    
     $friend_button='<button class="btn btn-warning" disabled>Add as a friend</button>';
     $block_button='<button class="btn btn-warning" disabled>Block user</button>';
     #logic for friend button
     if ($is_friend==TRUE) {
        $friend_button='<button name="unfreind_btn" class="unfreind_btn btn btn-warning">unfriend</button>';
    }
    elseif ($_SESSION['app']==TRUE&&$f_uname!=$session_uname&&$ownerblockviewer==FALSE) {
    $friend_button='<button name="friend_btn" class="friend_btn btn btn-warning">Request As friend</button>'; 
    }
    #logic for block button
    if($viewerblockowner==TRUE)
        {
        $block_button='<button name="unblock_btn" class="unblock_btn btn btn-warning">Unblock</button>';
        
        }
     elseif ($user_ok==TRUE&&$f_uname !=$session_uname) {
        $block_button='<button name="block_btn" class="block_btn btn btn-warning">Block</button>';
    }
    if (isset($_SESSION['app'])&&$session_uname!="") {
    
    
                       } else {
                          header("location: index.php");
                       }
    } catch (Exception $exc) {
        echo $exc->getTraceAsString();
    }
    ?>
    <div class="container-fluid">
    <br><div class="row"> </div><br>
    <div class="row">
        <div class="col-sm-2">
    
    
    </div>    
    <div class="col-lg-8">
    <div class="tab-content">
    <ul class="nav nav-tabs">
    <li><a href="#tabs-1" data-toggle="tab" class="profile">profile</a></li>
    <li class="active"><a href="#tabs-2" data-toggle="tab"class="articles">articles</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 ">
      <?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"><legend></legend>Phasellus mattis tincidunt nibh. Cras orci urna, blandit id, pretium vel, aliquet ornare, felis. Maecenas scelerisque sem non nisl. Fusce sed lorem in enim dictum bibendum.
    </div>
    <div id="tabs-4"class="tab-pane  fade gal_photos">
    <?php 
    include 'others/gallery.php';
    ?>    
    </div>
    <div id="tabs-5" class="tab-pane fade vids">Phasellus mattis tincidunt nibh. Cras orci urna, blandit id, pretium vel, aliquet ornare, felis. Maecenas scelerisque sem non nisl. Fusce sed lorem in enim dictum bibendum.
    </div>
    </div>
    
    
    </div>
    <div class="col-sm-2">
    
    
    </div>  
    </div>
    </div>
    <script type="text/javascript">
        var spinner='<img src="img/spinner.gif">';
    $(".fancybox-effects").fancybox();
    $("button.friend_btn").click(function(){
        $("button .friend-btn").show(spinner);
        alert("friend button clicked");
        var user_f=$(this).attr('user');
    $.post(function(){
        "parser/friend_sys.php",
        ({"user":user_f}),
        function(data){
            if(data==1){
            $(".block_btn").show();
            $(".unfriend_btn").show();
            }else{
                
            }
        }
    });
        $(".friend-btn").html(spinner).fadeOut(250);
    });
    </script>
    </body>
    </html>
    

    the friend_sys.php code is as follows:

     

    <?php
    include '../includes/dbconfig.inc.php';
    
    
    $session_f_uname=  htmlentities($_SESSION['uname']);
     $user=  htmlentities($_POST['user']);
     $sql="select count(user_id) from user where uname=':uname' and activated='1' limit 1";
     $stmt=$conn->prepare($sql);
     $stmt->bindparam(":uname", $session_f_uname);
    $stmt->execute();
    if($stmt->rowCount()<1)
    {
        echo 'user doesnt exist';
        exit();
    }
    if (isset($_POST['user'])) {
        $sql="select count(blocked_id) from blockedusers where blocker=':f_uname' and blockee=':session' limit 1";
        $stmt=$conn->prepare($sql);
        $stmt->bindparam(":f_uname",$user);
        $stmt->bindparam(":session",$session_f_uname);
        $stmt->execute();
        $block_count0=$stmt->rowCount();
        $sql1="select count(blocked_id) from blockedusers where blocker=':session' and blockee=':f_uname' limit 1";
        $stmt1=$conn->prepare($sql1);
        $stmt1->bindparam(":f_uname",$user);
        $stmt1->bindparam(":session",$session_f_uname);
        $stmt1->execute();
        $block_count1=$stmt1->rowCount();   
        $sql2="select count(friend_id) from friends where friend_one=':session' and friend_two=':f_uname' and accepted='1' limit 1";
        $stmt2=$conn->prepare($sql2);
        $stmt2->bindparam(":f_uname",$user);
        $stmt2->bindparam(":session",$session_f_uname);
        $stmt2->execute();
        $row_count0=$stmt2->rowCount();
        $sql3="select count(friend_id) from friends where friend_one=':f_uname' and friend_two=':session' and accepted='1' limit 1";
        $stmt3=$conn->prepare($sql3);
        $stmt3->bindparam(":f_uname",$user);
        $stmt3->bindparam(":session",$session_f_uname);
        $stmt3->execute();
        $row_count1=$stmt3->rowCount();
         $sql4="select count(friend_id) from friends where friend_one=':session' and friend_two=':f_uname' and accepted='0' limit 1";
        $stmt4=$conn->prepare($sql4);
        $stmt4->bindparam(":f_uname",$user);
        $stmt4->bindparam(":session",$session_f_uname);
        $stmt4->execute();
        $row_count2=$stmt4->rowCount();
        $sql5="select count(friend_id) from friends where friend_one=':f_uname' and friend_two=':session' and accepted='0' limit 1";
        $stmt5=$conn->prepare($sql5);
        $stmt5->bindparam(":f_uname",$user);
        $stmt5->bindparam(":session",$session_f_uname);
        $stmt5->execute();
        $row_count3=$stmt5->rowCount();
    
    
        if ($block_count0[0]>0) {
            echo '<script>alert("This user has blocked you, We cannot proceed");</script>';
            exit();
        }
        elseif ($block_count1[0]>0) {
        echo '<script>alert("You must unblock this '.$user.'in order to proceed");</script>';
            exit();
    }
    elseif ($row_count0[0]>0 ||$row_count1[0]>0) {
    echo '<script>alert("You are already friends with this '.$user.'");</script>';
            exit();
    }
    elseif ($row_count2[0]>0) {
    echo '<script>alert("You already have a pending friend request already sent to '.$user.'");</script>';
            exit();
    }
    elseif ($row_count3[0]>0) {
    echo '<script>alert("'.$user.' has requested to friend with you first. Check your friend request");</script>';
            exit();
    }
     else {
        $sql="insert into friends (friend_one, friend_two,date_made) values(':session',':f_uname',now())";
    $stmt=$conn->prepare($sql);
    $stmt->bindparam(":session",$session_f_uname);
    $stmt->bindparam(":f_uname",$user);    
     $stmt->execute();
     echo '<script>alert("Friend request sent");</script>';
            exit();
     }
    
    
    
    
    }
    
    
    
    
    
    
    
    
    if (isset($_SESSION['app'])&&$session_f_uname!="") {
        header("location: ../home.php?u=".$session_f_uname);
    } else {
        header("location: ../index.php");
    }
    
    
    
  13. guys im trying to output photos from users folder but it is not showingup. the system works like this, i try to insert the filename based on time & reference it with in the user gallery folder and then try to output it. but it is not showing up but is inserting values in table. here is the code for photo_sys.php:

    include '../includes/dbconfig.inc.php';
    $photo= $_FILES['photo'];
    print_r($photo);
    if ($photo) {
    
    $name=basename($_FILES['photo']['name']);
    $t_loc=$_FILES['photo']['tmp_name'];
    $fileType = $_FILES["photo"]["type"];
    $fileSize = $_FILES["photo"]["size"];
    $fileErrorMsg = $_FILES["photo"]["error"];
    $kaboom = explode(".", $name);
    $fileExt = end($kaboom);
    $db_file_name = date("DMjGisY")."".rand(1000,9999).".".$fileExt;
    list($width, $height) = getimagesize($t_loc);
    if($width < 10 || $height < 10){
    header("location: ../message.php?msg=ERROR: That image has no dimensions");
    exit(); 
    }
    if($fileSize > 2000000) {
    header("location: ../message.php?msg=ERROR: Your image file was larger than 2mb");
    exit(); 
    } else if (!preg_match("/\.(gif|jpeg|jpg|png)$/i", $name) ) {
    header("location: ../message.php?msg=ERROR: Your image file was not jpg, gif or png type");
    exit();
    } else if ($fileErrorMsg == 1) {
    header("location: ../message.php?msg=ERROR: An unknown error occurred");
    exit();
    }
    $sql = "SELECT DISTINCT gallery FROM photos WHERE user='{$_SESSION['uname']}'";
    $stmth=$conn->prepare($sql);
    $stmth->execute();
    $fetch=$stmth->fetch(PDO::FETCH_ASSOC);
    $gallery=$fetch['gallery'];
    $dir1="../user/{$_SESSION['uname']}";
    $moveResult=move_uploaded_file($t_loc, $dir1.'/'.$name);
    if($moveResult){
    echo 'upload successful';
    include_once("img_resize.php");
    $wmax = 800;
    $hmax = 600;
    if($width > $wmax || $height > $hmax){
    $target_file = "../user/$log_username/$name";
    $resized_file = "../user/$log_username/$name";
    img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
    
    }
    $sql="INSERT INTO photos(user, gallery, filename, upload_date) VALUES ('{$_SESSION['uname']}','$gallery','$db_file_name',now())";
    $stmth=$conn->prepare($sql);
    $stmth->execute();
    header("location: ../home.php?u={$_SESSION['uname']}");
    exit();
    }
    else {
    echo "file not uploaded";
    }
    
    }

    here is the output code for the gallery in home.php:

    <div id="tabs-4"class="tab-pane fade gal_photos">
    <?php
    if ($_SESSION['uname']!="") {
    echo '<form id="photoform" enctype="multipart/form-data" method="post" action="others/photo_sys.php">'
    . '<h3> Hi '.$_SESSION["uname"].' please add a photo:<br>' 
    
    . '<input type="file" name="photo" accept="image/*" required>'
    . '<p><input type="submit" class="upload_button" name="up_img" value="Upload Photos"></p></form>';
    //select the user galleries
    $sql = "SELECT DISTINCT gallery FROM photos WHERE user='{$_SESSION['uname']}'";
    $stmth=$conn->prepare($sql);
    $stmth->execute();
    $fetch=$stmth->fetch(PDO::FETCH_ASSOC);
    $gallery=$fetch['gallery'];
    $id=$fetch['id'];
    $sql1="SELECT filename FROM photos WHERE user='{$_SESSION['uname']}' AND gallery='$gallery' And id='$id' ORDER BY RAND() LIMIT 1";
    $stmth1=$conn->prepare($sql1);
    $stmth1->execute();
    $fet=$stmth1->fetch(PDO::FETCH_ASSOC);
    $dir="user/{$_SESSION['uname']}";
    
    while ($row1 = $fet) 
    {
    $file=$row1['filename'];
    echo '<img src="$dir/$file" alt="$file"><br><br>';
    
    } 
    }
    else
    {
    echo 'please login to upload photos';
    }
    
    ?> 
    </div>
×
×
  • 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.