9 Replies - 1123 Views - Last Post: 10 April 2014 - 04:59 AM Rate Topic: -----

#1 dforthster   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 10-April 14

[HELP]how to retrieve/display data from database

Posted 10 April 2014 - 02:52 AM

i created login form displaying username but my problem is how can i show his first name where in the process of checking the login forms, only username and password input by users no first name and last name?

like welcome jef, your username is "anyusername" your age is 20

i hope guys you got my point, i really new to PHP.
Is This A Good Question/Topic? 0
  • +

Replies To: [HELP]how to retrieve/display data from database

#2 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2654
  • View blog
  • Posts: 10,586
  • Joined: 03-December 12

Re: [HELP]how to retrieve/display data from database

Posted 10 April 2014 - 03:04 AM

It depends what's in the database. Look at the mySQL tutorials for a starter.
Was This Post Helpful? 0
  • +
  • -

#3 HeadAche   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 7
  • Joined: 10-April 14

Re: [HELP]how to retrieve/display data from database

Posted 10 April 2014 - 03:16 AM

What you'd need to do is use a select statement,

so take the input from the form and store it in session variables ie:
$_SESSION['username'] = $_POST['username'];



and then a query:

$query = "Select First_Name, age from account where username = '$_SESSION['username']' Limit 1;
$result= mysqli_query($connect,$query);

if(!result) {
die(mysqli_error($connect));
}
else {
while($row = mysqli_fetch_array($result)){
$First_Name = $row['First_Name'];
$Age = $row['Age'];
}
}




and then you can use them:

 <h1> Welcome <?php echo $First_Name ?> you are <?php $age ?> years old! </h1>


This is only rough.

I would do some research on sessions, queries, and more importantly sanitizing inputs.
Was This Post Helpful? -1
  • +
  • -

#4 dforthster   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 10-April 14

Re: [HELP]how to retrieve/display data from database

Posted 10 April 2014 - 03:48 AM

i am getting this error

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\employee\register\login_success.php on line 17



how to fix
Was This Post Helpful? 0
  • +
  • -

#5 dforthster   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 10-April 14

Re: [HELP]how to retrieve/display data from database

Posted 10 April 2014 - 04:07 AM

or maybe you have a simple code that i can follow that does the same result please
Was This Post Helpful? 0
  • +
  • -

#6 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2654
  • View blog
  • Posts: 10,586
  • Joined: 03-December 12

Re: [HELP]how to retrieve/display data from database

Posted 10 April 2014 - 04:17 AM

As I said, look at the tutorials section to get started we will not write your code for you, you must put forth more effort than gimme code that works.
Was This Post Helpful? 0
  • +
  • -

#7 Atli   User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4240
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: [HELP]how to retrieve/display data from database

Posted 10 April 2014 - 04:23 AM

@HeadAche, please do not teach newbies how to code SQL Injection vulnerable code right of the bat. It's doing them a disservice, really. It's also why PHP devs have such a bad rep in the developer world, because the internet is littered with these kind of examples, that teach new coders poor and dangerous practices.

@dforthster, if you came here to get working code examples, you're out of luck. We don't do that. We'll be happy to guide you through writing your own though. Just show us what you try and tell us what is going wrong.

You may also want to go through some of our PHP Tutorials. We have some great tutorials on the basics of PHP-MySQL interaction. Some of them are pretty outdated though, so you may want to start with these two. They demonstrate how to use MySQL in PHP using modern techniques.

Introduction to PDO (Requires some OOP knowledge.)
Introduction to MySQLi and Prepared Statements
Was This Post Helpful? 1
  • +
  • -

#8 dforthster   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 10-April 14

Re: [HELP]how to retrieve/display data from database

Posted 10 April 2014 - 04:38 AM

View PostAtli, on 10 April 2014 - 04:23 AM, said:

@HeadAche, please do not teach newbies how to code SQL Injection vulnerable code right of the bat. It's doing them a disservice, really. It's also why PHP devs have such a bad rep in the developer world, because the internet is littered with these kind of examples, that teach new coders poor and dangerous practices.

@dforthster, if you came here to get working code examples, you're out of luck. We don't do that. We'll be happy to guide you through writing your own though. Just show us what you try and tell us what is going wrong.

You may also want to go through some of our PHP Tutorials. We have some great tutorials on the basics of PHP-MySQL interaction. Some of them are pretty outdated though, so you may want to start with these two. They demonstrate how to use MySQL in PHP using modern techniques.

Introduction to PDO (Requires some OOP knowledge.)
Introduction to MySQLi and Prepared Statements

okay sir. thanks
Was This Post Helpful? 1
  • +
  • -

#9 HeadAche   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 7
  • Joined: 10-April 14

Re: [HELP]how to retrieve/display data from database

Posted 10 April 2014 - 04:43 AM

An encapsed error is referring to quotes in your query.. You can look up how to correctly quote a session variable
Was This Post Helpful? 0
  • +
  • -

#10 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2654
  • View blog
  • Posts: 10,586
  • Joined: 03-December 12

Re: [HELP]how to retrieve/display data from database

Posted 10 April 2014 - 04:59 AM

Most answers can be found in the PHP DOCS
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1