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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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... Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.