rollOrDie Posted August 25, 2008 Share Posted August 25, 2008 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 More sharing options...
unkwntech Posted August 25, 2008 Share Posted August 25, 2008 It means that there is not a item named 'portId' being passed via the post so when you accessed $_POST['portId']; it raised an error. Link to comment https://forums.phpfreaks.com/topic/121207-solved-unidentified-index/#findComment-624816 Share on other sites More sharing options...
Fadion Posted August 25, 2008 Share Posted August 25, 2008 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 https://forums.phpfreaks.com/topic/121207-solved-unidentified-index/#findComment-624818 Share on other sites More sharing options...
rollOrDie Posted August 25, 2008 Author Share Posted August 25, 2008 Ahhh I was thinking the if (!$_POST['portId']) Bit would prevent the error, looks like I was wrong. Thanks Link to comment https://forums.phpfreaks.com/topic/121207-solved-unidentified-index/#findComment-624824 Share on other sites More sharing options...
unkwntech Posted August 25, 2008 Share Posted August 25, 2008 Use the code that GuiltyGear posted and that should clear it up. Then don't forget to mark the topic as solved... Link to comment https://forums.phpfreaks.com/topic/121207-solved-unidentified-index/#findComment-624827 Share on other sites More sharing options...
Fadion Posted August 25, 2008 Share Posted August 25, 2008 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 https://forums.phpfreaks.com/topic/121207-solved-unidentified-index/#findComment-624828 Share on other sites More sharing options...
rollOrDie Posted August 25, 2008 Author Share Posted August 25, 2008 Thanks thats fixed it! Yeah I agree, its better to fix a problem than to just tell it to shut up! Link to comment https://forums.phpfreaks.com/topic/121207-solved-unidentified-index/#findComment-624835 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.