You are currently viewing the BOOK: Beginning PHP 5.3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I am writing chapter codes and when I got everything ready, I tried the register script at the first time it worked fine, the problem is that :
- the script added only my username and the time (automatically),and none of
the other fields was added to the database.
- then I tried to register a new member more than 10 times, but every time I
got error told me that the Email address id already exists!!!!!! and I am sure there is email address similar in the db. so I tried a new register and I wrote in the email field just a regular name without @example.com and the same thing happen and keep telling me that the address exists.
PHP Code:
if ( member::getByEmailAddress( $member->getValue( "emailAddress" ) ) ) {
$errorMessages[] = '<p class="error">Sorry this email address is already exists!!!</p>';
}
this a new type of errors and I don't know where I have to chek, if any have an idea plz tell me.
thx
In the member class check the following method: getByEmailAddress the method will return true if the email address is in use thus giving you the error message. What check it does depends on what's in the method.
I tried to see but there is no error at the function, even I copied the getByUsername() function and pasted it, then I changed the variable and username to emailAddress, so I am sure the error not from this function.
thank you for your help.
Last edited by nawar youssef; October 28th, 2011 at 10:49 PM.
Well the error could be coming from the getValue method of the member class, also if the name of the POST array element is not 'emailAddress' but rather 'emailaddress' you'll also get an error. As the method will be looking for 'emailAddress' in the POST array when it will not exist.
Or put another way PHP array elements are case sensitive, example;
for the first check, when u told me to check at the getValue func, I this is my getValue() func,
Code:
public function getValue($field) {
if ( array_key_exists($field, $this->data) ) {
return $this->data[$field];
}else {
die("Field not found!!! / getValue() function");
}
}
I got no 'emailAddress', I got the variable $field !!! in the dataObject.class.php, to make it work with any field would call the function getValue, but in the member.class.php I got no getValue even!!!!
is that a mistake ?
>>>>>>>>>>>>>
And for the code you write I did not get your point, do you want me to try the code for the solution or just is an example.?? sorry for that
I did not got it, I feel like I am missing something, and is not easy to figure out what is it, so I am gonna restudy chapters 13 and 14, maybe I can solve the error, and then I will post here what I got, see you.