Imoddedu Posted June 9, 2011 Share Posted June 9, 2011 Hey! I get the error: Notice: Undefined offset: 1whenever I run this code: // Filter and Split Email $splitemail = explode('@', $email); if(checkdnsrr("$splitemail[1]")) { $email = mysql_real_escape_string($email); } else { $error = '2'; } Shouldn't there be a $splitemail[1]? Link to comment Share on other sites More sharing options...
Err Posted June 9, 2011 Share Posted June 9, 2011 Check if there is a $splitemail[1]. var_dump($splitemail);Removed the double quotation marks around $splitemail[1]. Link to comment Share on other sites More sharing options...
Ingolme Posted June 9, 2011 Share Posted June 9, 2011 Maybe it's considering "1" as a string because it was placed between quotation marks. Link to comment Share on other sites More sharing options...
trinistorm Posted June 9, 2011 Share Posted June 9, 2011 I'm guessing your passing explode a String; $email. Explode expects an array and will treat a string as an array of characters ie: me@gmail.com becomes->"m","e","@","g","m","a","i","l",".","c","o","m" Therefore when you say $splitemail[1] there isn't any members in this array so you have an undefined offset as $email was never exploded. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 9, 2011 Share Posted June 9, 2011 Explode uses a string, implode uses an array. I'm assuming the only thing to do is to remove the quotes around the variable. Otherwise, use print_r to print the array to see what it contains. Link to comment Share on other sites More sharing options...
Imoddedu Posted June 10, 2011 Author Share Posted June 10, 2011 I think that might've helped, but I still don't ever get $error set to anything.Here is the whole code: // Validate form startif ($_POST) { $username = $_POST['username']; $password = $_POST['password']; $firstName = $_POST['fname']; $lastName = $_POST['lname']; $passwordb = $_POST['passwordb']; $email = $_POST['email']; $###### = $_POST['######']; $age = $_POST['age']; $country = $_POST['country']; $ip = $_POST['ip']; // validate /* CHECK FOR FILLED FIELDS */ if ( ($username || $password || $firstName || $lastName || $passwordb || $email) == "") { $error = '1'; } else { $error = '0'; } /* CHECK FOR FILLED FIELDS */ /* EMAIL VALIDATION */ if ( filter_var($email, FILTER_VALIDATE_EMAIL) == TRUE) { $email = $email; } else { $error = '2'; } // Filter and Split Email $splitemail = explode('@', $email); if(checkdnsrr($splitemail[1])) { $email = mysql_real_escape_string($email); } else { $error = '2'; } /* EMAIL VALIDATION */ if($error = '0') { // real escape the strings: // insert data to DB $query = sprintf("INSERT INTO customers(username,password,firstName,lastName,######,age,email,country,ip) VALUES ('$username','$password','$firstName','$lastName','$######','$age','$email','$country','$ip');", mysql_real_escape_string(md5($password))); mysql_query($query); $error = '99'; } }?> Link to comment Share on other sites More sharing options...
Err Posted June 10, 2011 Share Posted June 10, 2011 Your very last IF statement is assigning 0 to $error instead of checking for it. Change it to if ($error == '0') {, note the two equal signs.I'm just making an observation here but variables should start with a letter and not with any other symbol. So you can't do $####, try to change it to a word that has meaning. Link to comment Share on other sites More sharing options...
ShadowMage Posted June 10, 2011 Share Posted June 10, 2011 I'm just making an observation here but variables should start with a letter and not with any other symbol. So you can't do $####, try to change it to a word that has meaning.I'm guessing the forum automatically censored the original variable name. I think it's supposed to be that little 3-letter word for gender... Link to comment Share on other sites More sharing options...
Imoddedu Posted June 10, 2011 Author Share Posted June 10, 2011 I'm guessing the forum automatically censored the original variable name. I think it's supposed to be that little 3-letter word for gender...Yea, it is. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.