php Notice: Undefined index: id in C:\xampp\htdocs\includes\middle.php on line 3
I am making a website and am getting thrown this error when I go to www.mydomain.org. This code Works when going to http://mydomain.org/index.php?id=home How do I fix this as I don’t want people to have to type in the /index.php?id=home
2 Answers 2
Check if it is set, if not, set it to ‘home’:
$page = isset($_GET['id']) ? $_GET['id'] : 'home';
Then you don’t need an if statement to check it is set:
Ah much thanks. I actually do still need the if statement. It throws a syntax error if it is removed, but it works with your added line how I want it to.
You shouldn’t need an if statement anymore to check that the variable has value. You will need to check whether the value is a ‘valid section’ of your site though.
Notices are really recent in PHP development, and they are not errors, which means you don’t have to fix them. Yet, this is a very good practise to do so.
The undefined index notice warns you that you are trying to read an array index that hasn’t been initialised. In your case, you try to read the home index of the $_GET array. When your URL is something.php?home=something , then $_GET[‘home’] is initialised automatically, and no notice appears. However, when you access something.php , this index isn’t set, which explains the notice !
In your code, you need to check whether this index is set, and assign it a default value when it isn’t.
$page = isset($_GET['home']) ? $_GET['home'] : 'home';
Got error message from Xampp Notice: Undefined index [php]
The form is working (showing) and the empty error message also working but i have these messages in the header. What is the problem and the solution please ?
Those are not errors, they are notices. Reason for them is that $_POST does not contain such entries.
Because your initial PHP code is running when the form loads the first time. Wrap them in a check to see if the form has been submitted.
2 Answers 2
Your logic is off. First check if the submit is pressed, then check if any of your inputs are empty.
Plus, it looks as if your entire code is inside the same file, in turn giving you those notices. As soon as your page loads, it throws those errors.
if(empty($u_name) or empty($u_pwd) or empty($u_email))< echo "Error
"; > else < echo "All fields were filled."; >> ?>
I also noticed that you may be attempting to store passwords with MD5. This is not recommended and is quite old and no longer considered safe to use as a password storing function.
Important sidenote about column length:
If and when you do decide to use password_hash() or crypt, it is important to note that if your present password column’s length is anything lower than 60, it will need to be changed to that (or higher). The manual suggests a length of 255.
You will need to ALTER your column’s length and start over with a new hash in order for it to take effect. Otherwise, MySQL will fail silently.
Cannot access to localhost/xampp/index.php
I just installed XAMPP for windows 7, control panel seems to work fine, I started MySql and Apache, the problem I have is, when I type localhost in my browser «Google Chrome» it sends me to «http://localhost/dashboard/» when I change the url to «//localhost/xampp/index.php», it tells me: «Object not found! The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again. If you think this is a server error, please contact the webmaster. Error 404 localhost Apache/2.4.16 (Win32) OpenSSL/1.0.1p PHP/5.6.11» anyone can helps me out with this? Thanks.
it can also be index.html :), not necessary that it will only have index.php file in the xampp root folder
3 Answers 3
Ok, Create a page yourpage.html / yourpage.php whatever, you have to put all your pages in a folder in C:\Xampp\htdocs\ dir
Then try accessing following url:
I understand what you are trying to tells me, however I don’t want to make a website yet, i want to access the main page of the xampp, which i can add a password and stuff like that
I think you should be entering «http://localhost/index.php», because there is no such file in my ../htdocs/xampp/ folder called as index.php.
So may be the file you are referring to is in ../htdocs/index.php and to access it you need to hit the url as «http://localhost/index.php».
In Xampp the default page will redirect you to /Dashboard Folder because it is sending the header Location:http://localhost:80/Dashboard to browser and browser understands that and redirects it.
The answer by @Sumeet Gavhale is correct. And instead of C://Xampp/htdocs folder xampp use to host contents inside /htdocs folder so if you want to find C://Xampp/htdocs/index.php type localhost/index.php (but that will redirect you to /htdocs/Dashboard folder).
If you want to change the hosting folder you should edit the Apache http/https configuration file (but that depends on your OS and file system).
Note : The Default Page Word referred in second line of this answer means the document’s name in the default documents in your Server (xampp in your case) (for eg: index.htm ,index.html , index.php etc). Will be loaded in your server and will be different in other’s case (if they have done that) (index.php in first case (if not edited)).
Index.php Of Xampp’s Source Code
else < $uri = 'http://'; >$uri .= $_SERVER['HTTP_HOST']; header('Location: '.$uri.'/dashboard/'); exit; ?>Something is wrong with the XAMPP installation :-(
But if you still want to view (execute) the page enter «//» in front of last and second last line.
How to turn off notice reporting in xampp?
On a remote server there is no problem, but in localhost (xampp 3.1.) I cannot turn off reporting notices.
Notice: Undefined index: Fname in D:\xampp\htdocs\xx\php01\form01.php on line 6
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED ; Development Value: E_ALL ; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT ; http://php.net/error-reporting error_reporting = E_ALL & ~E_NOTICE //shouldn't this line turn off notice reporting ?
Why would you want to turn off notices for development? Personally in Dev environment, I believe you should use E_ALL and that is it. Have you checked that you are not changing this value at run time?
The best course of action is to fix the errors. Notices are errors, but ones the program can recover from. $Fname = isset($_POST[‘Fname’]) ? $_POST[‘Fname’] : »;
@MikeBrant, it is long story about my experimenting with php. I simply want to know how to exclude them.
5 Answers 5
Write this code in start of your file.
ini_set('display_errors', 0); error_reporting(E_ERROR | E_WARNING | E_PARSE);
If you did not want to use above lines then you have to write @ before $_POST to suppress notices, like
With this line error_reporting = E_ALL & ~E_NOTICE also change display_errors = Off although its bad programming practices.
Noor, thanks, it works, but in that case I must write these lines on each file. Why it is not possible to do on php.ini level ?
Your php.ini file with this code error_reporting = E_ALL & ~E_NOTICE should absolutely does the trick. Not sure why its not working with you. Are you using any framework/CMS may be there error_reporting is set again to true
Noor, no framework, no cms. But if you don’t see any error in my php.ini line — let’s say solved. Who knows what could be the real reason. Thanks, anymore.
If your running XAMPP and want to turn off notices (or other features):
1. Make sure your editing the right INI file (select config from the control panel)
2. Turn display_errors=on
3. Turn error_reporting=E_ALL & ~E_NOTICE (This will only suppress notice errors)
4. Important — Make sure XAMPP is not overriding your settings further down the file (read the notice above the first set of settings)
5. Stop and Start Apache after saving the file
Try to do a phpinfo(); just before your $Fname = $_POST[«Fname»]; line. What’s the error_reporting property value ? See this or this to understand the value displayed in the table.
If it’s not what you expected, check that the property is not changed by php. It’s also possible you edited the wrong php.ini file : XAMPP tends to copy the original php.ini file and create his own. Use phpinfo(); , search for ‘php.ini’ string in the table : you will find the path of the php.ini file used.
Last thing, maybe the problem is that you did not properly restarted apache after you changed php.ini file. The thing is that xamp is a distinct process of the apache service. Closing XAMP do not make apache service to be stopped, you better use XAMPP Control Panel to stop/start apache.