0

For some reason I can't get UPDATE to work, after hours of googling I can't seem to find a working code.

$stmt = $con->prepare("UPDATE user_settings SET accept_emails = ? WHERE user= '$user'");
$stmt->bind_param('s', '0');
$stmt->execute(); 
$stmt->close();

Trying to update via Ajax, keeps returning 500 Server Error. Should I just use the old MySQL way?

Brian
  • 296
  • 3
  • 15
  • 1
    check your error log for more details !! – Abhik Chakraborty Apr 05 '14 at 21:34
  • 6
    Why are you using `bind_param` for the literal, but not the variable? That's backwards! – Barmar Apr 05 '14 at 21:34
  • 2
    @Brian without seeing the rest of your code it would be hard to tell you what is wrong **unless you check the `error_log` and tell us what error it shows there.** – Prix Apr 05 '14 at 21:36
  • 1
    Check the return value of `$con->prepare()`, and print `$con->error` if it fails. – Barmar Apr 05 '14 at 21:36
  • 2
    "Should I just use the old MySQL way?" No. Hitting a single error is no reason to abandon your code; you just need to find out what the error was so you have a better starting point for research. [This post might be helpful for that](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12772851#12772851), and remember that you can load a URL which would normally be an AJAX response in an ordinary browser tab. – IMSoP Apr 05 '14 at 21:54
  • 1
    Also, is `accept_emails` really a string-type column? I don't use MySQL regularly, so maybe it doesn't matter, but if it's actually an integer, then you should be using the `'i'` type specifier. – IMSoP Apr 05 '14 at 21:56
  • @prix how do I enable a error_log for WAMPSERVER? – Brian Apr 05 '14 at 23:19
  • I also enabled Error Logs on my WAMPSERVER and nothing is coming up..And the code isn't working stil. – Brian Apr 05 '14 at 23:37

1 Answers1

1

i am pretty sure you can't use a literal in bind only variables. This is what you should use.

$var="0";

$stmt = $con->prepare("UPDATE user_settings SET accept_emails = ? WHERE user=?");
$stmt->bind_param('ss',$var,$user);
$stmt->execute(); 
$stmt->close();
Poorya Mohammadi
  • 751
  • 1
  • 8
  • 18