Old 21-06-2008, 16:54   #1 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
From database to browser

PHP Code:
<?php

session_start
();
if(!
session_is_registered(username)){
header("location:../login.php");
}

$host="xxx.net"
$db_username="yyy";
$db_password="sss";
$db_name="ttt";
$tbl_name="Information";


// Make a MySQL Connection
mysql_connect("$host""$db_username""$db_password") or die(mysql_error());
mysql_select_db("$db_name") or die(mysql_error());

// Retrieve all the data from the "$tbl_name" table
$result mysql_query("SELECT * FROM $tbl_name")
or die(
mysql_error());  

// store the record of the "example" table into $row
$row mysql_fetch_array$result );
// Print out the contents of the entry 

echo "First Name: ".$row['First_Name'];
echo 
"Last Name: ".$row['Last_Name'];

    if(isset(
$_POST['send'])) {
    
session_destroy();
    
header("location: logout.htm"); 
    }


?>

I followed this whole thing from a tutorial. But first of all, it doesnt seem like this code takes the First name and Last name from a specific person ("SELECT * FROM $tbl_name WHERE username=$username_in_session and password=$password_in_session")

Never the less this code isnt working for me :S I stored inputted username and password into session and now i just need it to connect to the database, find where it has that username and password, and so that it outputs the customer information on the page. Could some one help me out

Thanks. Any help is welcome!
  Reply With Quote
Old 21-06-2008, 17:01   #2 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,931
If $username_in_session and the other are text strings as opposed to number you must use LIKE '$username_in_session' not = $username_in_session.
__________________
  Reply With Quote
Old 21-06-2008, 17:02   #3 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,931
("SELECT * FROM $tbl_name WHERE username LIKE '$username_in_session' and password LIKE '$password_in_session'")
__________________
  Reply With Quote
Old 21-06-2008, 17:10   #4 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
Ya. I had that, but now how can take data from the database and put it somewhere onto the page. Like when i save a session and go to the next page i can put <?php echo $_SESSION["username"]; ?> somewhere and then the username will appear. Is there something that is same concept but with database information? and once i have retrieved the data from the database, what else do i need?
  Reply With Quote
Old 21-06-2008, 17:18   #5 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,931
__________________
  Reply With Quote
Old 21-06-2008, 17:24   #6 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
I know how to use sessions. Im just not sure how to output database data
  Reply With Quote
Old 21-06-2008, 17:32   #7 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,931
Do you mean this?

<?php echo $row['First_Name']; ?>
__________________
  Reply With Quote
Old 21-06-2008, 17:33   #8 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,931
Or do you want a loop where you can output multiple rows?
__________________
  Reply With Quote
Old 21-06-2008, 17:36   #9 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,931
Code:
$result = mysql_query("SELECT * FROM database WHERE mykey LIKE '%$search%'",$db); if ($myrow = mysql_fetch_array($result)) { do { $body = nl2br($myrow[body]); $body = stripslashes($body); echo $body; } while ($myrow = mysql_fetch_array($result)); } else{ echo "<h2>No records found to match your enquiry.</h2>"; }
__________________
  Reply With Quote
Old 21-06-2008, 21:24   #10 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,545
You don't need to use 'like' for strings - they will work fine with equal signs, and when you are doing username and password, it could potentially run into problems as it may return information for names and passwords that are like ones in the database when they aren't exact. With usernames and passwords, you want something to be exact!
__________________
This space for rent.

Dads Japan
Dudes Japan
  Reply With Quote
Old 21-06-2008, 23:14   #11 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
PHP Code:
<?php

session_start
();
if(!
session_is_registered(username)){
header("location:../login.php");
}

$host="xx.net"
$db_username="yy";
$db_password="zz";
$db_name="gg";
$tbl_name="Customer_Information";

mysql_connect("$host""$db_username""$db_password") or die(mysql_error());
mysql_select_db("$db_name") or die(mysql_error());
$result mysql_query("SELECT * FROM $tbl_name WHERE username='$username' and account_password='$password'")
or die(
mysql_error());  

$row mysql_fetch_array$result );

echo 
$row['First_Name']." - ".$row['Last_Name'];

    if(isset(
$_POST['send'])) {
    
session_destroy();
    
header("location: logout.htm"); 
    }


?>

This is my PHP. what is wrong with it? its not outputting any first name or lastname
  Reply With Quote
Old 21-06-2008, 23:19   #12 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
First_Name and Last_Name are the labels of the column where the first and last names are inputted
  Reply With Quote
Old 21-06-2008, 23:32   #13 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
Being a newbie and all. I forgot to set $_SESSION["username"] = $username;
$_SESSION["password"] = $password;

BIG OPPPS. Thanks anyways guys.

peace-out
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8