Current location: Hot Scripts Forums » Programming Languages » PHP » Displaying variables from the database


Displaying variables from the database

Reply
  #1 (permalink)  
Old 05-14-04, 07:07 PM
mishmia mishmia is offline
New Member
 
Join Date: May 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Talking Displaying variables from the database

Hey guys,

Could any1 gimme an example of how to display a variable after pullin it out of the database.??

Thanx,

Desperately,
Mishmia
Reply With Quote
  #2 (permalink)  
Old 05-14-04, 07:18 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

Assuming that you are using MySQL, check these out - they all contain great examples:

mysql_fetch_assoc:
http://ca2.php.net/manual/en/functio...etch-assoc.php

mysql_fetch_array:
http://ca2.php.net/manual/en/functio...etch-array.php

mysql_fetch_row:
http://ca2.php.net/manual/en/functio...-fetch-row.php

Generally, if there are more than 2 different fields I am pulling out, I will go with mysql_fetch_assoc() for code readability, but it's up to you and the rest of your code which one to go with.

Or one of the easiest MySQL/PHP tutorial I can find:

http://hotwired.lycos.com/webmonkey/99/21/index3a.html

Good luck then!
__________________
Blavv =|
Reply With Quote
  #3 (permalink)  
Old 05-14-04, 07:42 PM
mishmia mishmia is offline
New Member
 
Join Date: May 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Question

Thanks!

When a user logs in, I want the webpage to say " Hello User". I m unable to do this..Here is my code...I dunno whats the error...

Login Page Code:

<?
session_start();
include 'dbinfo.php';
// Conver to simple variables
$username = $_POST['username'];
$password = $_POST['password'];

if((!$username) || (!$password)){
echo "Please enter ALL of the information! <br />";
include 'index.php';
exit();
}

$password = md5($password);

$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
$login_check = mysql_num_rows($sql);

if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
// Register some session variables!
session_register('username');
$_SESSION['username'] = $username;
session_register('email');
$_SESSION['email'] = $email;

mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'");
header("Location: login_success.php");
}
} else {
echo "<font color=red>You could not be logged in! The username and passsssword do not match!</font><br />
Please try again!<br />";
include 'index.php';
}
?>

Login Success Page : ( When the user successfully logs in the system...)

<?php
require 'config.php';
session_start();
echo "Welcome ". $_SESSION['username'] ."! <br /><br />";
?>

Why am i just getting just the "Welcome !" message (

Thanks again
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
help with displaying variables tisza PHP 9 12-22-03 05:08 PM
Extract variables from a database andreasberglind ASP.NET 1 08-28-03 09:17 AM


All times are GMT -5. The time now is 10:33 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.