-2

The following function is not working. I cannot see why.

function access_apply($email,$pwd,$forname,$surname,$postcode,$telephone,$mobile){
    global $cnx;
    $pwd = bcrypt_hash($pwd);
    $q = $cnx->prepare("INSERT INTO `users` (email, pwd, forename, surname, postcode, telephone, mobile) VALUES (:email, :pwd, :forename, :surname, :postcode, :telephone, :mobile)");
    $q->execute(array(':email' => $email, ':pwd' => $pwd, ':forename' => $forename, ':surname' => $surname, ':postcode' => $postcode, ':telephone' => $telephone, ':mobile' => $mobile));
}

Once it is called the code breaks and nothing further is executed.

Walrus
  • 19,801
  • 35
  • 121
  • 199
  • 2
    "Breaks" how? What happens? What error messages are you getting? – Pekka Feb 03 '13 at 17:27
  • Can't turn on the error messages as it is loaded by ajax but the function is simply not working as if there is an error in the code somewhere – Walrus Feb 03 '13 at 17:28
  • Turn them on anyway and look in the developer console what the error message is. Without an error message, this is a guessing game and will attract garbage guessing game answers. – Pekka Feb 03 '13 at 17:29
  • [How to squeeze error message out of PDO?](http://stackoverflow.com/q/3726505) – Pekka Feb 03 '13 at 17:30

2 Answers2

4
  1. You need to turn on error reporting.
    You're experiencing "member of non-object" error but don't see it.
  2. You need to turn on exceptions for the PDO to see why you're getting above error.

So, add this code at the top of your script:

error_reporting(E_ALL);
ini_set('display_errors',1);

and this after connect:

$cnx->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

to see what happens on ajax request use Firebug (Net tab, Response section)

OR - much better! -

enable error logging and watch all the errors in the web-server's error log.
to do that change previous setting and add other one

ini_set('display_errors',0);
ini_set('log_errors',1);
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • 2
    Yeah, but why do all this hard work when next time he has this problem, he can *simply come back to Stack Overflow and ask another question?* And so we approach 5 Million questions limit. Sigh.... – Pekka Feb 03 '13 at 17:49
0

Looks like it might be a typo in the function parameters. One is $forname, and you assign $forename in the array. So it may be an undefined variable, or a parameter count mismatch that is occurring.

Levi
  • 12,214
  • 14
  • 43
  • 47