Solved

Retrieving results from query using PHP and MS Access database

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WordPress syntax 2 27
WordPress TK Title 8 25
How can I upload multiple images from a HTML form? 2 18
Before I get too far.. best way to save dates data 4 16
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 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

13 Experts available now in Live!

Get 1:1 Help Now