0

please I need your help I watch a lot of videos and I follow them step by step and I cant handle this problem

im using the session tag from the sign-up page and use it at the user panel to fetch his data from the userdata table in the database so it means every user sign up its must the remember his new user that been accepted and use it here to fetch his data hope I make it clear the prob is I cant fetch data using a variable in my example is $signinup

<?php 
session_start();

$serv = '127.0.0.1';
$user = 'root';
$pass = 'root';
$dbname = 'akbase';

// db base connection
$pdo = new PDO('mysql:dbname='.$dbname.';host='.$serv.'; charset=utf8',$user,$pass);

/* i want to use the Session to fetch data from database
the value of this session tag is any new sign up user name
and by using echo it show me the value of any new user */
echo $signinup = $_SESSION["username"] ;

$password = $_SESSION["password"] ;

// here i use prepare statment
$sql = 'SELECT * FROM usersdata WHERE username = :useruser';
$statement= $pdo->prepare($sql);
$statement->execute(':useruser'=>$signinup);
$data =  $statement->fetchObject();

echo $data->username ;

?>

this is the database table

enter image description here

This is the error message enter image description here

1 Answers1

2

You should replace this line:

$statement->execute(':useruser'=>$signinup);

By this:

$statement->execute(array(':useruser'=>$signinup));
T. AKROUT
  • 1,719
  • 8
  • 18
  • 3
    Or, if using php 5.4+, you could do `$statement->execute([':useruser'=>$signinup]);` :). Also, I would add to your answer what it is your actually doing. Saying something as simple as "`execute()` takes an array as a parameter" can clear up a lot of confusion for people who don't know what they are looking at, making your answer much better. – GrumpyCrouton Nov 10 '17 at 15:25
  • 1
    Absolutly @GrumpyCrouton – T. AKROUT Nov 10 '17 at 15:39
  • thank you, for me cuz, it's been a long time that I didn't deal with database and queries so I said if I want to fetch only one row I shouldn't use the array function cuz I'm not gonna looping but the new features are awsome – Ayoub Chafik Nov 10 '17 at 15:45
  • @AyoubChafik Since you are using PDO, I can recommend you the [PDO wrapper class](https://github.com/GrumpyCrouton/GrumpyPDO) that I wrote. Using this class, you can condense your entire query into 1 line of code, at the same time not harming readability. – GrumpyCrouton Nov 10 '17 at 15:49
  • Oh thank you ill try it now after ready the documention – Ayoub Chafik Nov 10 '17 at 17:17