Jump to content

[SOLVED] Unidentified Index


rollOrDie

Recommended Posts

Im getting an error for a relatively simple script that basically just inserts form information into a database. I never used to have the problem, but I suppose I must have just made one small change to the script that has messed things up!

 

Here is the error that Im getting:

Notice: Undefined index: portId in C:\xampp\htdocs\xampp\mattPealingDesign\script\php\project\projectProcess.php on line 10

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

 

Here is the code near line 10 (with the if statement being line 10 itself):

if ($_POST['portId'])
{
	$portId = $_POST['portId'];
}

 

The thing is, the data still enters the database without any problems! So I think this is just a warning? But I don't see why its coming up?

Link to comment
https://forums.phpfreaks.com/topic/121207-solved-unidentified-index/
Share on other sites

try

 

<?php
if(isset($_POST['portId'])){
    $porId = $_POST['portId'];
}
?>

 

You have an error in your query too.

 

EDIT: Just to explain this, the Notice comes out because the "portId" can't be found, as $_POST is still not set. Using the isset() you check if the post variables is set first, then assign it a value.

Ahhh I was thinking the

 

if (!$_POST['portId'])

 

Bit would prevent the error, looks like I was wrong. Thanks

 

Actually that bit will just check if $_POST['portId'] is empty, not if it is set or not. The Notice you are having isn't a fatal error and won't stop the script execution (and you can hide them), but it's always better to fix problems on the first place even if they aren't critical.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.