This question already has answers here:
How to validate an Email in PHP?
(7 answers)
Closed 8 years ago.
Hello I want to check if email is valid like blabla#blabla.com and not like just plain text 'BLbalbalba'.
I have this function:
function VerifyEmail($address)
{
$Syntax='#^[w.-]+#[w.-]+.[a-zA-Z]{2,5}$#';
if(preg_match($Syntaxe,$adrdess))
return true;
else
return false;
}
And checking it like this:
$email = htmlentities($_POST['email']);
if (!empty($email) && !empty($password) && !empty($message) && VerifyEmail($email) === true) {
Getting these errors:
Notice: Undefined variable: Syntaxe in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20
Notice: Undefined variable: adrdess in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20
Warning: preg_match() [function.preg-match]: Empty regular expression in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20
Notice: Undefined variable: Syntaxe in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20
Notice: Undefined variable: adrdess in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20
Warning: preg_match() [function.preg-match]: Empty regular expression in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20
Why is this happening? What did I do wrong? Is it a stable way of checking if email is valid?
Thanks!
No, it's not "stable", it's not "valid", and it will not do a good job. use
filter_var($email, FILTER_VALIDATE_EMAIL)
instead. relevant docs: http://www.php.net/manual/en/function.filter-var.php
some spelling mistakes here
should be
function VerifyEmail($address)
{
$Syntax='#^[w.-]+#[w.-]+.[a-zA-Z]{2,5}$#';
if(preg_match($Syntax,$address))
Related
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 8 years ago.
Not sure why I'm getting this error as the code is working and I can see the data I expected.
Code
$allSales = array();
foreach ($game['sales'] as $sale) {
foreach ($sale['values'] as $id => $values) {
$allSales[$id]+=$values['y'];
}
}
Error 1
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Filename: player/game.php
Line Number: 81
Error 2 (Same Code)
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 1
Filename: player/game.php
Line Number: 81
The statement:
$allSales[$id] += $values['y'];
means to take the current value of $allSales[$id], add the value of $values['y'] to it, and store that result back in $allSales[$id]. But the first time that you encounter a particular $id, there is no $allSales[$id]. This results in the warning when you try to get its current value.
Change to:
if (isset($allSales[$id])) {
$allSales[$id] += $values['y'];
} else {
$allSales[$id] = $values['y'];
}
Or you could just prefix the line with # to suppress warnings (I know purists will cry over this):
#$allSales[$id] += $values['y'];
how can i hide the php notice by solving the issue.
my code
if(empty($_GET['mode']) && !$_GET['page']) {
include($basepath.'/templates/template.home.php');
}
Notice: Undefined index: page in /var/www/public_html/index.php on line 1
i tried like this
if(empty($_GET['mode']) && !isset($_GET['page']) && !$_GET['page']) {
include($basepath.'/templates/template.home.php');
}
but still showing the
Notice: Undefined index: page in /var/www/public_html/index.php on line 1
how can i solve/fix it ?
The problem is that you use in both statements !$_GET['page'] when using && operator.
When you use !$_GET['page'] in both cases even if you added !isset($_GET['page'] this condition is checked in $_GET['mode'] is empty.
You simple should probably change your statement from:
if(empty($_GET['mode']) && !$_GET['page']) {
include($basepath.'/templates/template.home.php');
}
into
if(empty($_GET['mode']) && !isset($_GET['page'])) {
include($basepath.'/templates/template.home.php');
}
In this case simple if $_GET['page'] is not set (and of course mode is empty) you should include homepage template
Either mode or page isn't present in the array $_GET - so you need to test for it using array_key_exists
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 9 years ago.
Receiving the following:
Notice: Undefined index: func in /Applications/XAMPP/xamppfiles/htdocs/select2/func.php on line 23
Notice: Undefined index: func in /Applications/XAMPP/xamppfiles/htdocs/select2/func.php on line 67
Notice: Undefined index: func in /Applications/XAMPP/xamppfiles/htdocs/select2/func.php on line 114
Here are the offending lines:
Line 23
if($_GET['func'] == "drop_1" && isset($_GET['func'])) {
drop_1($_GET['drop_var']);
}
function drop_1($drop_var)
{
Line 67
if($_GET['func'] == "drop_2" && isset($_GET['func'])) {
drop_2($_GET['drop_var']);
}
function drop_2($drop_var)
{
Line 114
if($_GET['func'] == "drop_3" && isset($_GET['func'])) {
drop_3($_GET['drop_var']);
}
function drop_3($drop_var)
{
I looked in the existing questions and didn't find an answer where an if statement was attached with the operator &&.
Thanks,
Change the order of your condition to this:
if(isset($_GET['func']) && $_GET['func'] == "drop_1" )
Now you are checking if the 'func' index is set first before using it.
You have the order of your logical operators backwards. First you need to check to see if the variable is set and then you need to check it's value. If the first check is false then the second one will never happen due to short circuiting which prevents the error message you see.
if($_GET['func'] == "drop_1" && isset($_GET['func'])) {
should be:
if(isset($_GET['func']) && $_GET['func'] == "drop_1") {
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
Undefined index in PHP
Notice: Undefined index: NAME in C:\xampp\htdocs\pmsx\lib\config.php on line 107
That's the exact error. Here's my code on the file. Thanks for those will help.
here's my line 107:
//echo "<br>" . $cdata;
// create the proper tree node if NAME attribute is set
if ($this->attr["NAME"] != "")
$this->tags[count($this->tags) - 1] = $this->attr["NAME"];
Pastie link
Use isset() first, to check, whether the property exists at all.
if ( isset( $this->attr["NAME"] ) && ($this->attr["NAME"] != "") ) {
$this->tags[count($this->tags) - 1] = $this->attr["NAME"];
}
You error says, that the property NAME does not exist at all in the array attr!
NAME isn't a defined index. You probably want:
if( isset($this->attr['NAME']) && $this->attr['NAME'] != "" ) {
// ...
What you probably want is !empty($this->attr['NAME']) instead of $this->attr["NAME"]!="". Otherwise it errors out when NAME index is… well… undefined.
I am trying to install a arcade script and keep getting these errors, can anyone help out?
Notice: Undefined index: do in C:\xampp\htdocs\meggiemoos\arcade\install\new.php on line 34
Notice: Use of undefined constant sql - assumed 'sql' in C:\xampp\htdocs\meggiemoos\arcade\install\new.php on line 34
Notice: Undefined index: do in C:\xampp\htdocs\meggiemoos\arcade\install\new.php on line 37
Notice: Use of undefined constant sql2 - assumed 'sql2' in C:\xampp\htdocs\meggiemoos\arcade\install\new.php on line 37
This is line 34 to 38
<? if ($_GET['do'] == sql) {
include ('sql1.php');
}
else if ($_GET['do'] == sql2) {
include ('sql2.php');
I have tried if isset($_GET but I might have done it wrong as of the closed bracket { for next line, I was told to add another bracket as well but never told where.
Thanks for your help :)
Try
if (isset($_GET['do']) && $_GET['do'] == 'sql')
sql by itself is nothing to PHP. You need to have it as a string or variable, as follows:
<? if ($_GET['do'] == "sql") {
or
$var = "sql";
<? if ($_GET['do'] == $var) {
As for the line 37 error, the server cannot find the GET variable named 'do', so you need to find out why it's not being set. You might consider adding this to earlier parts of your script:
if (!isset($_GET['do'])) {
exit("do variable was not set!");
}
else {
$do = $_GET['do'];
}
That way, you don't have to keep typing $_GET['do'], which can get tedious.