-1

我的 PHP/SQL 表单代码没有输出任何东西。我尝试调试它并回显变量,但仍然没有运气。在某些情况下,我为调试注释了回声,但它们不起作用。我对高级 php 了解不多,我认为该错误与 SQL 数据库连接有关,但 or die 不起作用。我是初学者。

<?php
define('DEBUG', TRUE);
echo "Starting...<br>";
//TIMEZONE SET
date_default_timezone_set('America/New_York');
//VERSION VARIABLES--------------------------------------------------------------------        -----------
$sysversion = '1';
//TIME DEPENDANT VARIABLES-------------------------------------------------------------    ------------
$maxyear = '2004';
$minyear = '1890';
//USER INPUT VARIABLES-----------------------------------------------------------------------------
$email = mysql_real_escape_string($_POST['email']);
$username = mysql_real_escape_string($_POST['username']);
$pass1 = mysql_real_escape_string($_POST['pass1']);
$pass2 = mysql_real_escape_string($_POST['pass2']);
$first = mysql_real_escape_string($_POST['first']);
$last = mysql_real_escape_string($_POST['last']);
$sex = mysql_real_escape_string($_POST['sex']);
$bdaymonth = mysql_real_escape_string($_POST['bdaymonth']);
$bdayday = mysql_real_escape_string($_POST['bdayday']);
$byear = mysql_real_escape_string($_POST['bdayyear']);
$country = mysql_real_escape_string($_POST['country']);
$telcc = mysql_real_escape_string($_POST['telcc']);
$ac = mysql_real_escape_string($_POST['ac']);
$exc = mysql_real_escape_string($_POST['exc']);
$sta = mysql_real_escape_string($_POST['sta']);
$teltype = mysql_real_escape_string($_POST['teltype']);
$question = mysql_real_escape_string($_POST['question']);
$answer = mysql_real_escape_string($_POST['answer']);

//LOGICAL VARIABLES----------------------------------------------------------------------------------
if($pass1 == $pass2)
{
$password = $pass1;
}
echo "<br>$password<br>";
else
{
        echo "<script type='text/javascript'>\n";
        echo "alert('The passwords do not match.');\n";
        echo "window.location = 'http://nematznetwork.no-    ip.org/login/register.htm';\n";
        echo "</script>";
        echo 'PASS_ERROR';
}
if($byear < $maxyear)
{
$bdayyear = $byear;
echo "$bdayyear<br>";
}
else
{
        echo "<script type='text/javascript'>\n";
        echo "alert('You must be 10 years old to register.');\n";
        echo "window.location = 'http://nematznetwork.no-ip.org/login/register.htm';\n";
        echo "</script>";
        echo 'ERROR';
}
if($byear > $minyear)
{
$bdayyear = $byear;
echo "$bdayyear<br>";
}
else
{
        echo "<script type='text/javascript'>\n";
        echo "alert('You are older than the worlds oldest person. Please enter     your correct age.');\n";
        echo "window.location = 'http://nematznetwork.no-    ip.org/login/register.htm';\n";
        echo "</script>";
        echo 'ERROR';
}
$telnum = "$ac$exc$sta";
echo "$telnum<br>";
$regdate = date('Ymd,H:i:s');
echo "$regdate<br>";
function create($username, $password)
    {
        //MYSQL HEADERS----------------------------------------------------------------------------------------------------
        $database = mysql_connect("localhost" , "root" , "PassWord123456789");
           if(!$database)
        {
            if(DEBUG)
            {
            die("Failed to connect to database: " . mysql_error());
        }
            return FALASE;
        }
    echo "$database<br>";
        mysql_select_db("nematznetwork", $database);
        //MYSQL WRITE QUERY--------------------------------------------------------------------------------------------------
        $queryw = "
        INSERT INTO users (email, username, password, first, last, sex,     bdaymonth, bdayday, bdayyear, country, telcc, telnum, teltype, question, answer, sysversion, regdate) 
        VALUES($email, $username, $password, $first, $last, $sex, $bdaymonth,     $bdayday, $bdayyear, $country, $telcc, $telnum, $teltype, $question, $answer, $sysversion, $regdate)
        ";
        //MYSQL INSERT COMMAND
        mysql_query ($queryw, $database)
        //GET USER ID
        $queryr = "SELECT * FROM users WHERE username = '" . $username ."'";
    echo "$queryr<br>";
    $resource = mysql_query($queryr, $database);
    if(!$resource)
    {
        if(DEBUG)
        {
            die("Failed to query database: " . mysql_error());
        }
        return FALASE;
    }
        //echo "$resource<br>";
    $result = mysql_fetch_assoc($resource);
        //echo "$result<br>";
    $id = $result['ID'];
        //echo "$id<br>";
    //MAKE USER DIRECTORY
    $path = './../users/' . $id . '/';
        //echo "$path<br>";
    mkdir($path)
        //WRITE HTML FILES
    $file = './../users/' . $id . '/default.htm';
        //echo "$file<br>";
    $write = '<html>\n<head>\n<meta http-equiv="Content-Language" content="en-us">\n<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">\n<title>' . $first $last . '- NematzNetwork</title>\n</head>\n<body bgcolor="#FFFFFF" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">\n<iframe src=../../menu.htm width="100%" height="45" frameborder="0" scrolling="no" target="_parent"></iframe>\n<iframe src="body.htm" width="100%" height="90%" frameborder="0">\n</body target="_parent">\n</html>';
        //echo "$write<br>";
    file_put_contents($file , $write);
    $file2 = './../users/' . $id . '/body.htm';
        //echo "$file2<br>";
    $write2 = '<html>\n<head>\n<meta http-equiv="Content-Language" content="en-us">\n<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">\n<title>NematzNetwork</title>\n<base target="_parent" />\n</head>\n<body bgcolor="#FFFFFF">\n\n</body>\n</html>';
        //echo "$write2<br>";
    file_put_contents($file2 , $write2);
    //REDIRECT TO LOGIN PAGE-------------------------------------------------------------------------------------------------
    //echo "<script type='text/javascript'>\n";
    //echo "window.location = 'http://nematznetwork.no-ip.org/login/default.htm';\n";
    //echo "</script>";
}

?>

4

3 回答 3

1

您仅在其中一个函数内连接到数据库,当您执行长序列的函数时,该函数尚未执行mysql_real_escape_string()。m_r_e_s()必须与数据库建立有效/打开的连接才能运行,因此您所做的就是为所有这些变量分配一个布尔值 FALSE - m_r_e_s() 在失败时返回的错误值。

然后,您通过在函数的查询调用中使用超出范围的变量来复合错误,因此您将插入 NULL/未设置的变量。基本的 PHP 范围规则:

<?php
$foo = 'bar';
function baz() {
   echo $foo; // undefined function, because $foo is not in-scope
}
于 2013-06-02T02:39:23.660 回答
0

你做错了。

  1. 你有函数 create(),但你没有调用它。
  2. 不要使用 mysql_*。
  3. 如果要将变量保留在函数之外,请使用 global。“全球 $email, $first, $last, $sex, $bdaymonth, $bdayday, $byear, $country, $telcc, $ac, $exc, $sta, $teltype, $question, $answer;"
  4. 清理你的代码。它几乎不可读。阅读更多信息: http: //pear.php.net/manual/en/standards.php
于 2013-06-02T03:07:46.847 回答
0

要跟踪未出现的问题,请尝试添加

ini_set('display_errors', 1);
error_reporting(E_ALL);

如果默认 php 配置被抑制,这将强制显示 php 错误。

于 2013-06-02T04:57:11.427 回答