Undefined index

hello, i’m newbie in php…
I got this on browser when I tried to open the file :

Notice: Undefined index: status in C:\xampp\htdocs\penempahan\sprosessokong.php on line 16

please someone help me to solved my problem… its urgent…

here the code :

<?php include ('Connections/penempahan.php') ;

$con = mysql_connect("localhost", "penempahanuser", "1234");
if (!$con){
	die('Could not connect: ' . mysql_error());

mysql_select_db("penempahan", $con);

//table borangpermohonan

$sql=mysql_query("UPDATE borangpermohonan set status='disokong' where nogaji='$nogaji'");


please help me…tq

Hi azreen, welcome to the forum

I guess it doesn’t help that almost everywhere the PHP documentation refers to array “keys” yet the Notice message says “index”. (technically correct as PHP indexes the array keys, but a bit confusing just the same)

“undefined” can be for several reasons, but the main thing is it means “not created” or “can’t find it” for whatever reason.

Notices are not Errors or even Warnings, but IMHO they are something that should be looked into and corrected if possible.

Both $_GET and $_POST are (global) arrays and they can have either numeric or associative (string) keys.

So those Notice messages are saying “As ar as this PHP script can determine, the $_POST array does not have a member with the key that is the string status”

Where are the values for nogaji and status coming from - a form (which method) or a query string?

Be aware that the old mysql_* extension which you’re using is deprecated in version 5.5 of PHP (the current version) and is being removed from version 7 (the next version). You need migrate over to using either the mysqli_* extension or PDO

You’re also a sitting duck for SQL Injection attack as user submitted data is being let near the database without having first been **validated **and at the very least escaped (use of prepared statements is best)

You need to update what you are saying. PHP 7 has been the current version for several days now.

7.1 is the next version.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.