当我用表单运行post方法时,我的PHP页面几乎是空白的。我想知道这是谷歌云平台的问题还是我将应用程序加载到谷歌云平台上的方式的问题。这是我的应用程序
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
这是我的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';
}
?>
这是我的数据库.php页面:
<?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');
?>
最后,这里有一个php的例子,它在上一个表单的操作页面上运行:
<?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;
}
}
?>
我应该注意的是,我正在为CloudSQL和应用程序引擎上运行的内容收取免费积分,而且这些数据看起来像是进入了数据库,所以结果页面上的代码似乎正在工作。我们将不胜感激。
处理人员看起来不错,但接下来我们有;入口点:
这意味着handler.php文件决定将请求发送到哪里。
从这个文件中,我们看到"/result_contact.php"需要"result_contact.php",因此"contact.html"将是第42行到第52行的POST请求的来源。
由于代码中没有任何元素会导致显示变为空白(显式(,因此这是PHP驱动的,很可能与代码有关。由于PHP只通过第109或115行在result_contact.PHP中添加了一个echo,因此应该考虑返回这些值。