Solved

Retrieving results from query using PHP and MS Access database

Posted on 2007-11-26
1
669 Views
Last Modified: 2013-12-12
I am fairly new to programming in PHP.  Most of my skills lay with ASP and Flash, but in this case, I must use PHP to access a database.  The database is MS Access, which provides the portability we require.  Anyway, I'm simply trying to store retrieved information into an array, then pull up selected information as I need it.  With that selected information, I'll be accessing the database again to retrieve all data pertinent to that "user" and displaying the results in a table as I see fit.  My problem is getting the information....well actually, my problem is everthing.  I can't seem to get past retrieving my query and storing in an array then pulling that information.

Secondly, I'm trying to use functions to call the db access script.  I'm having problems identifying the global variables, although I thought I'd done it.  Any help would be great.  I know there are some syntax issues that I could avoid, such as the concanting of strings to variables, but I'm so use to it that it is hard to stop.
<?php
 
$db = realpath("dbase/tracker.mdb");
$db_conn = new COM('ADODB.Connection');
$db_conn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".$db);
 
$strSQL = "SELECT * FROM users WHERE username='". $username ."'";
 
$rs = $db_conn->Execute($strSQL);
 
$userdata = $rs;
$rs->Close();
$db_conn->Close();
 
echo("<td>Logged As: $userdata['firstname'] $userdata['lastname']</td>");
 
//........
//Later on I'm going to populate different dropdown fields with information based on the particular column name
 
?>

Open in new window

0
Comment
Question by:seanmac1068
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 21

Accepted Solution

by:
nizsmo earned 125 total points
ID: 20353244
Your code probably didn't run as you had some syntax errors in the echo statement:
<?php
 
$db = realpath("dbase/tracker.mdb");
$db_conn = new COM('ADODB.Connection');
$db_conn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".$db);
 
$strSQL = "SELECT * FROM users WHERE username='". $username ."'";
 
$rs = $db_conn->Execute($strSQL);
 
$userdata = $rs;
$rs->Close();
$db_conn->Close();
 
echo "<td>Logged As: " . $userdata['firstname'] . $userdata['lastname'] . "</td>";
 
//........
//Later on I'm going to populate different dropdown fields with information based on the particular column name
 
?>

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question