无法打开php文件,源文件似乎为空

无法打开php文件,源文件似乎为空,php,apache,Php,Apache,当我试图从localhost(localhost/PrimaAppAndroid/register.php)打开文件register.php时,页面将保持白色,如果我试图查看源文件,页面将为空。如果我离开register.php中的php部分,即使我不更改html中的扩展php,它也可以正常工作 我看到了一个文件,我在我的apache2.conf文件的末尾添加了AddType应用程序/x-httpd-php.php,但没有任何更改。如何解决这个问题 资料来源如下: register.php &l

当我试图从localhost(localhost/PrimaAppAndroid/register.php)打开文件
register.php
时,页面将保持白色,如果我试图查看源文件,页面将为空。如果我离开
register.php
中的php部分,即使我不更改html中的扩展php,它也可以正常工作

我看到了一个文件,我在我的
apache2.conf
文件的末尾添加了
AddType应用程序/x-httpd-php.php
,但没有任何更改。如何解决这个问题

资料来源如下: register.php

<?php 
/*
Our "config.inc.php" file connects to database every time we include or require
it within a php script.  Since we want this script to add a new user to our db,
we will be talking with our database, and therefore,
let's require the connection to happen:
*/
    require("config.inc.php");
?>

<h1>Register</h1> 
<form action="register.php" method="post"> 
    Username:<br /> 
    <input type="text" name="username" value="" /> 
    <br /><br /> 
    Password:<br /> 
    <input type="password" name="password" value="" /> 
    <br /><br /> 
    <input type="submit" value="Register New User" /> 
</form>

config.inc.php
变量中没有分号?

另一个可能的错误源:

mysql_select_db($dbname, $conn) or ide("Database inesistente");
应该是

mysql_select_db($dbname, $conn) or die("Database inesistente");
再见,贾科莫布, 如果您正确发布了代码,则
config.inc.php
文件中有一个输入错误

mysql_select_db($dbname, $conn) or ide("Database inesistente");
正如您在最后看到的,您使用了
die
函数,但是您编写了
ide
,只要修复它,它就可以工作了

另外,您忘记了php变量末尾的分号

$username = "root"
    $password = "root"
    $host = "localhost"
    $dbname = "cinemapreverificasql"
一定是

$username = "root";
    $password = "root";
    $host = "localhost";
    $dbname = "cinemapreverificasql";

我注意到您的代码有错误,因为(;)在您声明的变量末尾丢失

<?php 

    // These variables define the connection information for your MySQL database 
    $username = "root";
    $password = "root";
    $host = "localhost";
    $dbname = "cinemapreverificasql";

    // Tis is the way we saw in class
    $conn = mysql_connect($host, $username, $password) or die("Errore nella connessione MySQL");
    mysql_select_db($dbname, $conn) or ide("Database inesistente");
?>


另一件事是尝试重命名文件config.inc.php,并将名称重新命名为config_inc.php

。它们不再得到维护。看到了吗?改为了解,并使用or-将帮助您决定使用哪个。检查您的PHP错误日志。允许您的应用程序以root身份连接到您的db从来都不是一个好主意。感谢您的建议,我在这里向您解释动机:在我参加测试的学校,我们必须使用此方法连接,因此我想尝试一下,看看它是否有效,我以根用户身份连接,因为这不是最终的应用程序,我刚刚创建了数据库,我只是尝试连接它。你尝试过我的建议吗?文件名是合法的,所以你建议重命名它是没有意义的。
<?php 

    // These variables define the connection information for your MySQL database 
    $username = "root";
    $password = "root";
    $host = "localhost";
    $dbname = "cinemapreverificasql";

    // Tis is the way we saw in class
    $conn = mysql_connect($host, $username, $password) or die("Errore nella connessione MySQL");
    mysql_select_db($dbname, $conn) or ide("Database inesistente");
?>