Current location: Hot Scripts Forums » Programming Languages » PHP » Having a hard time !


Having a hard time !

Reply
  #1 (permalink)  
Old 02-05-12, 02:19 AM
Finnseah Finnseah is offline
New Member
 
Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rolleyes Having a hard time !

Hey guys,

i have this error "Notice: Undefined index: email in C:\*******\*****\*******\******* on line 11" and on line 12 too .

I wrote this on my php


<?php

define ("DB_HOST","localhost"); // set database host
define ("DB_USER","root"); // set database user
define ("DB_PASS",""); // set database password
define ("DB_NAME","facebook"); // set database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("couldn't select database");

$user = $_POST ['email'];
$pass = $_POST ['pass'];


echo $user;
echo $pass;

?>

Please i need help real quick !
Reply With Quote
  #2 (permalink)  
Old 02-06-12, 05:53 AM
alxkls alxkls is offline
Newbie Coder
 
Join Date: Nov 2011
Posts: 98
Thanks: 0
Thanked 9 Times in 9 Posts
Code:
No syntax errors detected in /var/www/html/test.php
its a notice not an error, not to mention fatal error. your php.ini has been setup to show notices. however as far as i can see you are using some windows apache server so i have no clue where your php.ini is located. you could leave it like that while developing and when ready all you have to do is add
Code:
error_reporting(0);
at the top of your file and that will fix the problem.
Reply With Quote
  #3 (permalink)  
Old 02-06-12, 04:14 PM
sonic10 sonic10 is offline
New Member
 
Join Date: Jan 2012
Location: USA
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I agree with alxkls. The error message could mean that you are trying to read a variable that has not been set. This is only a warning and does not affect your script, it should behave as normal, you can change whether they are displayed or not via the php.ini file or by using error_reporting.

But checking to see if the variable has been set using isset() is and idea. If it is null you will get the notice you are receiving unless you turn error reporting off.

if(isset($_POST['email'])) {
Reply With Quote
  #4 (permalink)  
Old 02-07-12, 10:47 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Setting error_reporting to 0 does not fix the errors (or 'notices, if you want). It just hides them, and at the same time encourages bad coding.

As sonic10 pointed out, use isset() on user defined variables to make sure they exist before you attempt to use them.

Every time PHP throws a warning, error, or notice, it's been written to a log file. That means, every time is has to open, write and close the file. That makes your script run slower.
Reply With Quote
  #5 (permalink)  
Old 03-12-12, 06:11 PM
Frement Frement is offline
Newbie Coder
 
Join Date: Jul 2010
Posts: 19
Thanks: 0
Thanked 1 Time in 1 Post
I would invert the isset() and then use die() to kill the script if the user hasn't entered an email or a password. And I agree with Nico, never hide the warnings/errors/notices.
Reply With Quote
Reply

Bookmarks

Tags
php help needed


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tier 1 SAVVIS Network! DOUBLE RAM & DRIVES! FREE CP! FULLY MANAGED with Cpanel! mxhub General Advertisements 0 12-25-07 10:32 PM
Convert to time from a string Godwin PHP 2 09-26-06 12:25 AM
having Loop issues, help... Advanced todayscoffee PHP 2 02-27-06 12:36 AM
Super class seo services extreme90 General Advertisements 0 12-28-05 12:45 PM


All times are GMT -5. The time now is 09:03 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.