In my example, you could replace
echo $_POST['table_name'];
with
if(isset($_POST['table_nam
and get rid of the notice.
Main Topics
Browse All TopicsI have an html form whose values will be sent to php script using _post superglobal variable.
When I click on submit button it gives me the following in the PHP page.
Notice: Use of undefined constant table_name - assumed 'table_name' in F:\courses\CSCI5633\Spring
Notice: Use of undefined constant num_fields - assumed 'num_fields' in F:\courses\CSCI5633\Spring
here table_name and num_fileds are the names of text boxs present in html form. As these values will be stored in _POST super global variable (I have used post method in html form) I tried usinig these in php script it shows me the above errors.
Please help me
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Batalf, please think before you tell users that they should not care about notices. While it is true that in most cases a problem that generates a notice will not be a serious issue and should not affect the functionality of the script it IS still an error. It comes under the same category as the opinion that "notices don't matter because PHP can be configured to not show them", my opinion on that is you can hide the error but it will still be there.
Further more the cause you described is a little off the mark. That would cause an undefined index error not undefined constant. The undefined constant errors are usually caused by referencing $_POST[inputname] instead of $_POST['inputname']. Without the single quotes PHP takes it as you are referencing a defined constant so it is very important to include the quotes.
Take note that the interpreter assumes that you meant $_POST['inputname'] if the constant is not defined even if you left the quotes out so the code should still work as expected even with the notice displayed. This can make getting rid of the error a little difficult if you are not familiar with the cause.
In short: make sure you include the single quotes.
Diablo84,
Sorry!
You're probably right on the spot when it comes to the solution of this problem.
It wasn't my intention to let the user think that notices doesn't matter at all. My point was to inform that's there's a difference between notices and Parse/Fatal errors. It probably came out wrong in my post. I'm tired after a long day:-)
To use $_POST['inputname'] instead of $_POST[inputname] sounds logical as the solution here.
Batalf
Batalf,
That's no problem :). The vast majority of questions asked are from users who are still learning and so trust and rely on us to provide them with accurate information. If we can set them on the right path from the start they will benefit from it in the long run.
There are so many experts who are point hungry (and so post as quick as they can to make sure they get the points) that the quality of the answers has been decreasing over time. This is the main reason why i do not participate as much now. If my comments ever seem blunt it is as a result of many months of having to work around these people to maintain the standard, not to cause offence. My intention is to educate and sometimes being blunt is the most direct path.
Best Wishes,
Diablo84
Hi, nagulas.
Your MAIN problem with superglobal vars is that you're calling it like this
$_POST[table_name] instead of $_POST['table_name'] /* note the quote around table_name */
second problem with unset vars that are called is solved with checking if it is set
$_POST[table_name] = (isset($_POST[table_name])
/* that way you retain scope of variable and "avoid" notices */
Hope it is clear now.
cheers
I don't think you quite have it, or i may just not have followed what you have said. Either way:
When referencing array indexes (including the super globals) always use single quotes as a general rule. Without the quotes it looks for a constant of the specified name. If you are not familiar with constants you may wish to look here: http://us2.php.net/manual/
There is also a difference between double quotes and single quotes in PHP,
http://us2.php.net/manual/
The main factor is double quoted strings are parsed, single quoted strings are not, eg:
$var = 'my variable string';
echo "This is a string including $var"; //outputs: This is a string including my variable string
echo 'This is a string including $var'; //outputs: This is a string including $var
If you don't need to output variable values in a string then use single quotes so there is no unnecessary interpolation.
nagulas, if you're using arrays (superglobals or other ones) enclosed in double quotes, you don't need to enclose an index in quotes only if you're using simple syntax (not a complex one) or if type of index is not string.
$arr['xxx'] = 'some string';
echo "blaa blaa $array[xxx]"; // simple syntax - don't need single quotes
echo "blaa blaa {$array['xxx']}"; // complex syntax - need single quotes, if index is string
$arr[123] = 'some string';
echo "blaa blaa $array[123]"; // simple syntax - don't need single quotes
echo "blaa blaa {$array[123]}"; // complex syntax - works fine without single quotes because an index is not a string
why to use complex syntax? sometimes you have to use multidimensional arrays:
$array['x1']['y1'] = 'some string';
echo "blaa blaa $array[x1][y1]"; // this will output 'blaa blaa Array[y1]'
echo "blaa blaa {$array[x1][y1]}"; // this will output 'blaa blaa some string'
I made a mistake copying your code instead of mine. So again, to avoid those notices you must add this line of code for each var that generate notice..
$_POST['table_name'] = (isset($_POST['table_name'
/* just replace table_name with var that you're trying to use */
cherrs
HI Diablo84,
I am having problems with these superglobal variables on my server, but there is no need for me to keep in quotes on my desktop machine, why is that different on my server there is an old version of PHP it is 4.XX, but on my desktop I have installed latest version, is it because of version that I need to keep quotes.
nagulas,
"but there is no need for me to keep in quotes on my desktop machine"
It's not that there isn't a need for it, it's just your local machine is configured differently to your server so the error isn't displayed. As i mentioned before even though the error is not shown it is still there so it is good practice to get in the habit of writing clean code (ie. in this particular case make sure you include the quotes).
The usual set up is to have the error level configured to E_ALL on the development server to show ALL errors and the live server configured at a slightly lower level (therefore if anything should go wrong on the live site there are no unprofessional looking errors cluttering up the page). In any case the ideal situation is to have all errors shown using E_ALL as it will encourage you to write better code and obviously provides the extra aid with debugging.
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
Accept Batalf's comment {http:#13405230} as answer.
Any objections should be posted here in the next 4 days. After that time, the question will be closed.
Huji
EE Cleanup Volunteer
Business Accounts
Answer for Membership
by: BatalfPosted on 2005-02-25 at 09:48:16ID: 13405225
You shouldn't care that much about notices. If a checkbox called table_name isn't checked off before you post the form, this message would occure if you try to refer to it.
Example:
echo $_POST['table_name']; would produce that notice from PHP if the checkbox "table_name" isn't checked off.
Batalf