PHP每次都会白屏死机.我究竟做错了什么? [英] PHP white screen of death every time. What am I doing wrong?

查看:65
本文介绍了PHP每次都会白屏死机.我究竟做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于PHP和MySQL,我是一个完全的菜鸟,所以您知道我确实对HMTL和CSS有很多经验.我需要的是在我的站点上创建一个表单,以将表单中的信息上载到我的数据库.问题是单击提交"按钮只会打开一个空白标签,其中包含我的.php文件的地址,并显示空白屏幕. .php在下面.

I'm a complete noob to PHP and working with mysql so you know I do however have a great deal of experience with HMTL and CSS. All I need is for a form on my site to upload the information in the form to my database. The problem is that clicking the "submit" button just opens up a blank tab with the address of my .php file in it and displays a blank white screen. The .php is below.

<?php
$hostname = "myHostName";
$username = "PreRegCustomers";
$dbname = "PreRegCustomers";
$password = "myPassword";
$usertable = "CustomerInfo";

mysql_connect($hostname, $username, $password) OR DIE ("Unable to 
connect to database! Please try again later.");
mysql_select_db($dbname);

$sql = "INSERT INTO $usertable (firstName, lastName, streetAddress, city, state, zip, country, email, phone, badgeName) 

VALUES ('$firstName', '$lastName', '$streetAddress', '$city', '$state', '$zip', '$country', '$email', '$phone', '$badgeName')";

$sql="INSERT INTO $usertable (firstName, lastName, streetAddress, city, state, zip, country, email, phone, badgeName)

VALUES ('".$_POST[firstName]."', '".$_POST[lastName]."', '".$_POST[streetAddress]."', '".$_POST[city]."', '".$_POST[state]."', '".$_POST[zip]."', '".$_POST[country]."', '".$_POST[email]."', '".$_POST[phone]."', '".$_POST[badgeName]."')";
?>

现在,从我阅读的内容来看,这通常是由于代码中的某种错误引起的.这对我来说很难,因为我不太了解PHP,而且页面中的几乎所有内容都是取自其他人的代码.大部分来自代码的内容都来自godaddy.com(托管站点和数据库).

Now from what I've read this is usually caused by some kind of error in the code. This is difficult for me as I don't know PHP very well and almost everything in the page was taken from other peoples code. Most of it from the code helps from godaddy.com (where the site and database are hosted).

我已经过测试,以确保支持并启用了PHP.我有一个已经可以正常运行的表单邮件程序.我已经设置了DNS,尝试了多种不同的语法,并致电给技术支持以查看其是否有用,我已将网站从Windows迁移到了linux,并且我更改的所有内容都会产生完全相同的空白屏幕.我毫不怀疑,毕竟这将是一件非常容易修复或显而易见的事情,但是如果有人可以看看我所缺少的,我将不胜感激.

I've tested to make sure that PHP is supported and enabled and it is. I have a form mailer that already functions just fine. I have setup a DNS, I have tried multiple different syntaxes, I have called tech support to see if it is something on their end, I've migrated my sites from windows to linux and every thing I change results in the exact same blank white screen. I have no doubt that after all this it's going to be something that's stupidly easy to fix or blatantly obvious but if anybody could take a look and see what I'm missing I would be very grateful.

输入一些答案后的新代码.我仍然收到通知,它仍未在数据库中插入任何内容.

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$hostname = "myHostName";
$username = "PreRegCustomers";
$dbname = "PreRegCustomers";
$password = "myPassword";
$usertable = "CustomerInfo";

//connect to mysql
$link_id = mysql_connect($hostname, $username, $password);
if (!$link_id) {
    die("Unable to connect to database! Please try again later. error:".mysql_errno());
}
//make sure your DB exists
if (!mysql_select_db($dbname)) die ("Connected to mysql but could not connect to the DB. error:".mysql_errno());

//avoid sql_injection
$firstName = mysql_real_escape_string($_POST['firstName']);
$lastName = mysql_real_escape_string($_POST['lastName']);
$streetAddress = mysql_real_escape_string($_POST['streetAddress']);
$city = mysql_real_escape_string($_POST['city']);
$state = mysql_real_escape_string($_POST['state']);
$zip = mysql_real_escape_string($_POST['zip']);
$country = mysql_real_escape_string($_POST['country']);
$email = mysql_real_escape_string($_POST['email']);
$phone = mysql_real_escape_string($_POST['phone']);
$badgeName = mysql_real_escape_string($_POST['badgeName']);

//write the query
$sql = "INSERT INTO $usertable 
    (firstName, lastName, streetAddress, city, state, zip, country, email, phone, badgeName) 
    VALUES ('$firstName', '$lastName', '$streetAddress', '$city', '$state', '$zip', '$country', '$email', '$phone', '$badgeName')";

//then you'll need to execute the query :)
mysql_query($sql); 
?>

推荐答案

据我所知,这段代码只是连接到数据库并设置了变量$ sql.您实际上在任何地方执行查询吗?您正在做任何事情来在屏幕上打印一些东西吗?

From what I can tell, this code just connects to a database and sets a variable $sql. Are you actually executing the query anywhere? Are you doing anything to print something on the screen?

这篇关于PHP每次都会白屏死机.我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆