• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

Need help reading a PHP Array

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

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

    if(($viewreport) AND ($report['action'])) {
Ray PaseurCommented:
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
JeffAuthor Commented:
Good point Ray, Thanks!
JeffAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now