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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.