Jump to content

Recommended Posts

I want to display data on my webpage that is in one of my columns in my database.

 

Im using this script to do it, and the data is not showing up - Can anyone help?

<?

$host="localhost"; // Host name

$username="test"; // Mysql username

$password="****"; // Mysql password

$db_name="****"; // Database name

$tbl_name="****"; // Table name

 

echo $_SESSION['new'];

?>

Link to comment
https://forums.phpfreaks.com/topic/107140-php-connections/
Share on other sites

Okay, so you've posted some variables containing your database/table info.  So...where is your code that opens a database connection? Where is your code that queries your database to get the information you want?  Where is your code that makes it "show up," as you say?

Link to comment
https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549296
Share on other sites

Yep, actually I just wanted to make it simple for people to understand...

At the top of my page I have a

 

<?

session_start();

?>

 

Then later down the page, I want to display the data from the database - so Im using this

 

<?php echo $_SESSION['award']."

 

Its not called 'new' I shouldn't of put that on there, just was trying to simplify it ha, but yeah that is what Im doing - What I just described

Link to comment
https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549297
Share on other sites

Well I haven't had to use any

 

sql="SELECT * FROM $tbl_name";

$result=mysql_query($sql);

 

$rows=mysql_fetch_array($result);

 

So far Im just using the echo $_session

 

and its working for me showing the first name and last names, I just went a few more lines down the page, and now Im trying to displaying something different and its not working

 

 

Link to comment
https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549299
Share on other sites

Are you having trouble understanding...

 

I have a

<? php session_start(); ?>

 

At the top of my page...

 

Next, I have

 

<?php echo $_SESSION['first_name']." ".$_SESSION['last_name'];?>

 

To show the user's name and last name

Then I have a

 

<?php echo $_SESSION['award']; ?>

 

To show the award name the employee has gotten.

 

The question was - Why is it not working is there some sort of error in my code...But there wasnt. 

 

I hope that helps you understand what Im asking in a very straight forward manner.

Help Forums are for users to help one another...Code posted does not ALWAYS necessarily have to work, go read through some of the other topics you'll see not everyone's code works, hence why they're asking for help. So when you tell me to post code that 'actually works' I respectfully disagree with what you said - not everyones code has to work.

 

Anyway > I have fixed the problem, and believe it or not > it was a MySQL problem, something I had messed up in PHPMyAdmin.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549304
Share on other sites

I am really confused. If appears you are trying to output text variables (firstname, lastname, award). You are ECHOing session data. Yet you say your data is stored in the database. So which is it?

 

$_SESSION['award'] = "Medal of Honor";

 

You would then..

 

echo $SESSION['award'];

 

which would output "Medal of Honor".

 

However, if you are storing the data in a database that is a whole 'nother story. I think you are mixing sessions and databases up.

Link to comment
https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549352
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.