Solved

Retrieving results from query using PHP and MS Access database

Posted on 2007-11-26
1
664 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
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now