Hello, I’m trying to use form to post to a route, which puts the form data into a database, but I keep getting error 500 on it.
What’s wrong with this?
array(
"pattern" => "mc/list/add",
"action" => function($call) {
$db = new Database(array(
"type" => "mysql",
"host" => "127.0.0.1",
"database" => "gsponsor",
"user" => "root",
"password" => "root"
));
$subscribers = $db->table("subscribers");
$subscriber = $subscribers->insert(array(
"id" => "",
"email_address" => $_POST["email"],
"ip_signup" => "127",
"fname" => $_POST["fname"],
"lname" => $_POST["lname"]
));
return response::json(array(
"hh" => $subscriber
));
},
"method" => "POST"
)
Are there any errors in the output or in your PHP error log? Generally HTTP 500 comes from unhandled errors.
This is what comes up in my php_error.log
Apache and MySQL says nothing
[08-Nov-2015 03:04:02 Europe/Oslo] PHP Parse error: syntax error, unexpected 'use' (T_USE) in /Volumes/TheWiseGrey/WebServer/gsponsor. dev/site/config/config.php on line 93
[08-Nov-2015 03:04:02 Europe/Oslo] PHP Stack trace:
[08-Nov-2015 03:04:02 Europe/Oslo] PHP 1. {main}() /Volumes/TheWiseGrey/WebServer/gsponsor.dev/index.php:0
[08-Nov-2015 03:04:02 Europe/Oslo] PHP 2. Kirby->launch() /Volumes/TheWiseGrey/WebServer/gsponsor.dev/index.php:16
[08-Nov-2015 03:04:02 Europe/Oslo] PHP 3. Kirby->site() /Volumes/TheWiseGrey/WebServer/gsponsor.dev/kirby/kirby.php:704
[08-Nov-2015 03:04:02 Europe/Oslo] PHP 4. Kirby->configure() /Volumes/TheWiseGrey/WebServer/gsponsor.dev/kirby/kirby.php:566
Which line is line 93 in your config.php
?
$ch = curl_init();
Turns out I had to use localhost instead of 127.0.0.1, what’s strange is that I tried to used 127.0.0.1 on another site, and it worked.
Guess it sometimes lives its own life
Because I’m going to use $call later on, just haven’t gotten so far yet
Ah, alright. The difference is that localhost
uses the MySQL socket while 127.0.0.1
uses TCP to port 3306. That’s a quite strange API decision of MySQL and I have had this issue as well and was surprised, but well. If it works it’s alright. 