Jump to content

Ehsan_Nawaz

Members
  • Posts

    12
  • Joined

  • Last visited

Everything posted by Ehsan_Nawaz

  1. it is not a pdo method its is mysqli method here is my db_connection file <?php if (isset($HTTP_GET_VARS)) extract($HTTP_GET_VARS); if (isset($HTTP_POST_VARS)) extract($HTTP_POST_VARS); include("config.php"); $link=mysqli_connect($host_name,$user_name,$password); if (! $link) die ( "MySQL error !"); mysqli_select_db($link,$database) or die ( "mysqlerror $database :".mysqli_connect_error() ); ?>
  2. <?php include("db_connect.php"); if(isset($_POST["login"])){ require("config.php"); global $database; $stmt = $database->prepare("SELECT * FROM single WHERE email=:email"); $stmt->bindParam(":email", $_POST["email"]); $result = mysqli_query($conn, $sql); $stmt->execute(); $count = $stmt->rowCount(); if($count == 1){ $row = $stmt->fetch(); if($_POST["pass"] == $row["pass"]){ ($row["PASSWORD"]) ($_POST["pw"]) session_start(); $_SESSION["email"] == $row["email"]; header("Location: dashboard.php"); } else { echo "login Success"; } } else { echo "Login Error"; } } Fatal error: Uncaught Error: Call to a member function prepare() on string in C:\xampp\htdocs\mysqlilogin\Adminframe.php:35 Stack trace: #0 {main} thrown in C:\xampp\htdocs\mysqlilogin\Adminframe.php on line 35
  3. Hi Dear Team Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\demo\register.php:43 Stack trace: #0 C:\xampp\htdocs\demo\register.php(43): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\demo\register.php on line 43 $sql = "SELECT * FROM register WHERE username:username AND email:email"; $stmt = $cn->prepare($sql); $stmt->bindValue(":username",$username); $stmt->bindValue(":email",$email); $stmt->execute(); $user = $stmt->fetch(PDO::FETCH_ASSOC); if($user){ if($user["username"]==$username){ echo "Username Already exits"; }elseif($user["email"]==$email){ echo "Email Adress Already in USe"; } }else { $sql ="INSERT INTO register(name,username,email,password,ip_adress)VALUES(:name,:username,:email,:password,ip_adress)"; $stmt = $cn->prepare($sql); $stmt->bindParam(':name',$name); $stmt->bindParam(':username',$username); $stmt->bindParam(':password',$password); $stmt->bindParam(':ip_adress',$ip_address); if($stmt->execute()){ echo "Register Success"; } }
  4. Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\xampp\htdocs\portfilo\index.php:25 Stack trace: #0 C:\xampp\htdocs\portfilo\index.php(25): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\portfilo\index.php on line 25 here this error
  5. <?php require_once("config.php"); if(isset($_POST["register"])){ $firstname = $_POST["firstname"]; $lastname = $_POST["lastname"]; $username = $_POST["username"]; $email = $_POST["email"]; global $cn; $sql ="INSERT INTO reg(firstname,lastname,username,email,password) VALUES(:firstname,:lastname,:username,:email,:passowrd)"; $stmt = $cn->prepare($sql); $stmt->bindValue(":firstname",$firstname); $stmt->bindValue(":lastname",$lastname); $stmt->bindValue(":username",$username); $stmt->bindValue(":email",$email); $stmt->bindValue(":password",$password); $run=$stmt->execute(); if($run) { echo "Data Upload"; } } ?> here is my databse code <?php session_start(); $servername = "localhost"; $username = "root"; $password = ""; try { $cn = new PDO("mysql:host=$servername;dbname=login",$username,$password); $cn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo "Server Offline" . $e->getMessage(); } ?>
  6. When i add your recommend code in my profile.php page it show me a Expected type 'string'. Found 'array'.
  7. public function UpdateDetails($fn,$ln,$un,$em) { $this->validateFirstname($fn); $this->validateLastname($ln); $this->validatenewEmail($em,$un); if(empty($this->error_array)){ $query = $this->con->prepare("UPDATE users SET firstName=:fn, lastName=:ln, email=:em WHERE username=:un"); $query->bindValue(":fn",$fn); $query->bindValue(":ln",$ln); $query->bindValue(":em",$em); $query->bindValue(":un",$un); return $query->execute(); } return false; } here is my profile page <?php require_once("assest/header.php"); require_once("class/Account.php"); require_once("class/fillterform.php"); require_once("class/Constants.php"); if(isset($_POST["SaveButtonDetails"])) { $account = new Account($con); $firstName = filterform::sanitizerFormstring($_POST["firstName"]); $lastName = filterform::sanitizerFormstring($_POST["lastName"]); $email = filterform::sanitizerFormEmail($_POST["email"]); if($account->UpdateDetails($firstName,$lastName,$email,$userLoggedin)){ //Sucess echo "update"; } else { ///failure echo "No update"; } } ?> <div class="SettingContainers column"> <div class="formSection"> <form method="POST"> <h2> User Details</h2> <?php $user= new User($con,$userLoggedin); $firstName = isset($_POST["firstName"]) ? $_POST["firstName"] : $user->getfirstName(); $lastName = isset($_POST["lastName"]) ? $_POST["lastName"] : $user->getlastName(); $email = isset($_POST["email"]) ? $_POST["email"] : $user->getUsername(); ?> <input type="text" name="firstName" placeholder="Enter First name" value="<?php echo $firstName; ?>"> <input type="text" name="lastName" placeholder="Enter Last Name" value="<?php echo $lastName; ?>"> <input type="email" name="email" placeholder="Pleas Enter Email" value="<?php echo $email; ?>"> <input type="submit" name="SaveButtonDetails" value="Save" > </form> </div> <div class="formSection"> <form method="POST"> <h2> Update Password</h2> <input type="password" name="oldpassword" placeholder="Enter Old PassWord"> <input type="password" name="newpassword" placeholder="Enter New Password"> <input type="password" name="confirmpassword" placeholder="Confirm New Password"> <input type="submit" name="SavepasswordDetails" value="Submit" > </form> </div> </div> The problem is when i can update the data in profile.php page the can't update the data in phpmyadmin and now its (echo No update)
  8. <?php class Post{ private $user_obj; private $con; public function __construct($con, $user){ $this->con = $con; $this->user_obj = new User($con,$user); } public function submitPost($body,$user_to){ $body = strip_tags($body);////Removing HTML TAGS $body = mysqli_real_escape_string($this->con,$body); $check_empty = preg_replace('/\s+/', '', $body);//delte all spaces if($check_empty != ""){ //Current Date and time $date_added = date("Y-m-d H:i:s"); //get username $added_by = $this->user_obj->getUsername(); //if user have not a profile send to the none if($user_to == $added_by){ $user_to = "none"; } ////insert query $query = mysqli_query($this->con,"INSERT INTO posts VALUES('','$body','$added_by','$user_to','$date_added','no','no','0')"); $retured_id = mysqli_insert_id($this->con); //insert notification //Update post count for user $num_post = $this->user_obj->getNumPosts(); $num_post++; $update_query = mysqli_query($this->con,"UPDATE users SET num_post = '$num_post' WHERE username = '$added_by'" ); } public function loadPostsFriends(){ $str = ""; //string to return $data = mysqli_query($this->con,"SELECT * FROM posts where deleted = 'no' ORDER by id DESC"); while($row = mysqli_fetch_array($data)) { $id = $row['id']; $body = $row['body']; $added_by = $row['added_by']; $date_time = $row['date_added']; /// Creating user post on other user profile if($row['user_to'] == "none"){ user_to = ""; else { $user_to_obj = new User($con,$row['user_to']); $user_to_name = $user_to_obj->getFirstandLastname(); $user_to = "to <a href='" . $row['user_to'] . "'>" .$user_to_name . "</a>"; } // check if user account was closed $added_by_obj = new User($this->con,$added_by); if($added_by_obj ->isClosed()){ continue; } $user_details_query = mysqli_query($this->con,"SELECT first_name,last_name,profile_pic FROM users where username = '$added_by'"); $user_row = mysqli_fetch_array($user_details_query); $first_name = $user_row['first_name']; $last_name = $user_row['last_name']; $profile_pic= $user_row['profile_pic']; ///time stamp $date_time_now = date("Y-m-d H:i:s"); $start_date = new Date_Time($date_time);////Time_of_post $end_date = new Date_Time($date_time_now);///Current_time $intervel = $start_date->diff($end_date); if($intervel->y >< 1 ){ if($intervel ==1 ) $time_message = $intervel->y . " year ago";/// 1 Year Ago else $time_message = $intervel->y . " years ago"; //1+ year ago } else if($intervel-> m >= 1 ){ if($intervel->d == 0){ $days = " ago"; } else if($intervel->d == 1){ $days = $intervel->d."day ago"; } else { $days = $intervel->d."day ago"; } if($intervel->m == 1){ $time_message = $intervel->m." month".$days; } else $time_message = $intervel->m." months".$days; } } else if($intervel->d >= 1){ if($intervel->d == 1){ $days = "Yesterday"; } else { $days = $intervel->d."days ago"; } } else if($intervel->h >= 1){ if($intervel->h == 1){ $time_message = $intervel->h." hour ago"; } else { $time_message = $intervel->h." hours ago"; } } else if($intervel->i >= 1){ if($intervel->i == 1){ $time_message = $intervel->i." minute ago"; } else { $time_message = $intervel->i." minutes ago"; } } else{ if($intervel->s < 30){ $time_message = "Just Now"; } else { $time_message = $intervel->s." seconds ago"; } } $str .= "<div class='status_post'> <div calss='post_profile_pic'> <img src='$profile_pic' width='50'> </div> <div calss='posted_by' style='color#ACACAC;'> <a href = '$added_by'> $first_name $last_name </a> $user_to &nbsp;&nbsp;;&nbsp;;&nbsp;$time_message </div> <div id = 'post_body'$body<br></div> </div> " } echo $str; } } ?> When i run this code this show me the error Parse error: syntax error, unexpected 'public' (T_PUBLIC) in C:\xampp\htdocs\social\Classes\Post.php on line 39 the line 39 is public function loadPostsFriends() I check the code again and again but i cant find the error please help in this error
  9. Here is the config file code <?php ob_start(); session_start(); $timeOne = date_default_timezone_set("Europe/London"); $con = mysqli_connect("localhost","root","","social"); if(mysqli_connect_errno()){ echo"Filled to connect"; } ?>
  10. WHEN I START SESSION ERROR SHOW ME SESSION_START() (A SESSION HAD ALREADY BEEN STARTED)
  11. <?php require("config/config.php"); if(isset($_SESSION['username'])){ $userLoggedIn = $_SESSION['username']; $user_detail = mysqli_query($con, "SELECT * FROM users WHERE username='$userLoggedIn'"); $user = mysqli_fetch_array($user_detail); echo $user['First_Name']; } ?> In the Same Page line:33 --> <?php echo $user['First_Name']?> When i execute my code i show the error Notice: Undefined variable: user in C:\xampp\htdocs\social\include\header.php on line 33
×
×
  • 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.