Need help reading a PHP Array

Posted on 2009-02-20
Last Modified: 2012-05-06
I have some unexplained updates going on im my database so I wrote this report code to track what's happening. I am building an array to log into my database but I only want it to log if there is an update. In the places where there is an update I have place the following code:

if ($viewreport) $report['action'] = ("edit");

When I try to write to database only if the action is in the array

if(($viewreport) AND ($report['action'])) {
I get this error
"Notice: Undefined index: action in /var/www/html/account.php on line 323"

Thanks, Jeff


function show_report($report) {

	echo "<ul class=\"report\">\n";

	foreach($report as $r) {

		echo "<li>" . $r . "</li>\n";


	echo "</ul>\n";



$viewreport = 1;

if ($viewreport) $report = array();

if ($viewreport) $report["page"] = ("membreport.php"); 

if ($viewreport) $report['referrer'] = $_SERVER['HTTP_REFERER'];


$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'main';



if ($action == "addNow") {

if ($viewreport) $report['action'] = ("addNow");


$sql = "Querry goes here";

if ($viewreport) $report["query"] = ("$sql");





if ($action == "main") {


Contenent Here!



if($viewreport) { 

// Show report on Page

	echo "Referrer = " . $report['referrer'] . "<br>";

	echo "Page = " . $report['page'] . "<br>";

	echo "Action = " . $report['action'] . "<br>";




if($viewreport) { 	

// Insert Report in DB

	mysql_query("INSERT INTO tbltrkreport (referrer,page,action,query,other)

				VALUES ('" . $report['referrer'] . "','" . $report['page'] . "','" . $report['action'] . "','" . show_report($report) . "','')") or die ('Database error: MySQL Said : '. mysql_error());



Open in new window

Question by:jeffey48
    LVL 13

    Accepted Solution

    use isset($report['action']) to make sure that the value exist. i.e.

        if(($viewreport) AND ($report['action'])) {
    LVL 107

    Assisted Solution

    by:Ray Paseur
    A "Notice" is not an error - it is just a notice.  You can set error_reporting(E_ALL ^ E_NOTICE) and PHP will stop bothering you about the undefined variables.

    But you might want to stop using $_REQUEST in this script.  Instead use $_POST.  There is never any circumstance when you would want to update your data base on the basis of something that arrived in the $_GET string!

    Cheers, ~Ray

    Author Comment

    Good point Ray, Thanks!

    Author Closing Comment


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    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 dynamically set the form action using jQuery.

    728 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

    14 Experts available now in Live!

    Get 1:1 Help Now