ChompGator Posted May 25, 2008 Share Posted May 25, 2008 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']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/107140-php-connections/ Share on other sites More sharing options...
pocobueno1388 Posted May 25, 2008 Share Posted May 25, 2008 Where are you getting the variable $_SESSION['new'] from? Also, you would need to call session_start() at the top of the page in order to maintain the session. Quote Link to comment https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549295 Share on other sites More sharing options...
.josh Posted May 25, 2008 Share Posted May 25, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549296 Share on other sites More sharing options...
ChompGator Posted May 25, 2008 Author Share Posted May 25, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549297 Share on other sites More sharing options...
.josh Posted May 25, 2008 Share Posted May 25, 2008 Your session variable has nothing to do with your database information, unless you queried your database and put the results in it. Please refer to my previous post. Quote Link to comment https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549298 Share on other sites More sharing options...
ChompGator Posted May 25, 2008 Author Share Posted May 25, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549299 Share on other sites More sharing options...
ChompGator Posted May 25, 2008 Author Share Posted May 25, 2008 The column named award is in my database, and it has text in the column, and Im just trying to display the text and its not working, Im going to try something else though - I think I may know the problem - Will post - here if it doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549300 Share on other sites More sharing options...
.josh Posted May 25, 2008 Share Posted May 25, 2008 Okay well if it still doesn't work I suggest instead of posting random variables and code that does work, you post the code that isn't working and be a little more specific than "it's not working." Quote Link to comment https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549302 Share on other sites More sharing options...
ChompGator Posted May 25, 2008 Author Share Posted May 25, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549304 Share on other sites More sharing options...
.josh Posted May 25, 2008 Share Posted May 25, 2008 Well if you had bothered to read my post, you would see that I said to NOT post code that works. And what part of "the code you have posted has nothing to do with the problem you say you are having (with your database)" do YOU not understand? Quote Link to comment https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549306 Share on other sites More sharing options...
gamefreak13 Posted May 25, 2008 Share Posted May 25, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/107140-php-connections/#findComment-549352 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.