My PHP pages go nearly blank when I run a post method with a form. I want to know whether it's a problem with the Google Cloud platform or a problem with the way I loaded the application onto the Google Cloud Platform. Here is my app.yaml:
runtime: php
env: flex
runtime_config:
document_root: .
handlers:
- url: /(. \.(html|png|jpg|js|css))$
static_files: \1
upload: . \.(html|png|jpg|js|css)$
- url: /.*
script: auto
entrypoint:
serve handler.php
env_variables:
CLOUDSQL_USER: root
CLOUDSQL_DB: COSGymPatronData
CLOUDSQL_PASSWORD: ************
CLOUDSQL_DSN: /cloudsql/cosgym:us-central1:cosgympatrondata
Here is my handler.php:
<?php
ini_set('allow_url_fopen',1);
switch(@parse_url($_SERVER['REQUEST_URI'])['path']) {
case '/':
require 'index.php';
case '/index':
require 'index.php';
case '/index.php':
require 'index.php';
case '/result_contact.php':
require 'result_contact.php';
case '/checkout.php':
require 'checkout.php';
case '/loginAction.php':
require 'loginAction.php';
case 'signinAction.php':
require 'signinAction.php';
}
?>
And here is my database.php page:
<?php
function prepare_string($dbc, $string) {
$string = mysqli_real_escape_string($dbc, trim($string));
return $string;
}
define('DB_USER', get_env('CLOUDSQL_USER'));
define('DB_PASSWORD', get_env('CLOUDSQL_PASSWORD'));
define('DB_HOST', get_env('CLOUDSQL_DSN'));
define('DB_NAME', get_env('CLOUDSQL_DB'));
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die('Could not connect to MySQL: ' . mysqli_connect_error());
mysqli_set_charset($dbc, 'utf8');
?>
And finally, here's an example of the php that runs on the action page for the previous form:
<?php
require 'database.php';
$errors=[];
if(!empty($_POST['name'])) {
$name = $_POST['name'];
} else {
$name = NULL;
$errors[] = "<p>We need your name </p>";
}
if(!empty($_POST['email'])) {
$email = $_POST['email'];
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "<p>Your email is incorrect '$email' </p>";
$email = NULL;
}
}else{
$errors[] = "<p>We need your email </p>";
$email = NULL;
}
if(!empty($_POST['subject'])) {
$subject = $_POST['subject'];
} else {
$subject = NULL;
$errors[] = "<p>We need your subject </p>";
}
if(!empty($_POST['message'])) {
$message = $_POST['message'];
} else {
$message = NULL;
$errors[] = "<p>We need your message </p>";
}
$name_clean = prepare_string($dbc, $name);
$email_clean = prepare_string($dbc, $email);
$subject_clean = prepare_string($dbc, $subject);
$message_clean = prepare_string($dbc, $message);
$q = "INSERT INTO Contact(name, email, subject, message) VALUES(?, ?, ?, ?)";
$stmt = mysqli_prepare($dbc, $q);
mysqli_stmt_bind_param(
$stmt,
'ssss',
$name_clean,
$email_clean,
$subject_clean,
$message_clean
);
$result = mysqli_stmt_execute($stmt);
if (!$result)
{
$errors[]="<p>Error Access DB</p>";
}
if(count($errors)==0) {
echo "<p>Welcome to COS GYM Our managers will contact you</p>";
}else
{
foreach($errors as $err)
{
echo $err;
}
}
?>
I should note that I'm being charged on the free credits for what's running onto the CloudSQL and App Engine, and that data looks like it's going into the database, so it seems like the code on the results page is working. Help figuring this out would be appreciated.
CodePudding user response:
The configuration of AppEngine, when looking at the app.yaml, is not correctly defined. Let's take it apart one element at a time. runtime - this should be explicit, i.e. php73 or php74 or php55 runtime_config: this is incorrect and not part of this context as it belongs with the python runtime options in AppEngine
The handlers seem alright, but next we have; entrypoint:
This means the handler.php file determines where to send requests.
From this file we see '/result_contact.php' requires 'result_contact.php', so the 'contact.html' would be the source at lines 42 through 52 for the POST request in question.
As there are no elements in the code that would cause the display to go blank (explicitly), this is PHP driven, most likely to do with the code. As the PHP only adds an echo in result_contact.php through lines 109 or 115, you should consider returning these values.
