1

这是我在点击“注册”电子邮件发送后一直收到的错误,但是当我在 activate.php 下激活它时,它给了我这个错误..:

Unknown column 'active' in 'field list'

我确实知道它希望我将该字段添加到我相信的数据库中。但是我不知道如何将其添加到数据库中的代码,例如名称和所有内容。因此它可以完全正常工作并与此脚本一起使用..

这是 Activate.php 脚本代码:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>GamesFX > Sign up</title>
    <link href="css/style.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <!-- start header div -->   
    <div id="header">
        <h2>GamesFX > Sign up</h2>
    </div>
    <!-- end header div --> 

    <!-- start wrap div --> 
    <div id="wrap">
        <!-- start PHP code -->
        <?php

            mysql_connect("info here", "my stuff", 

"this is fine") or die(mysql_error()); // Connect to database server(localhost) with 

username and password.
            mysql_select_db("mysql works fine connecting") or die(mysql_error()); // Select 

registration database.

            if(isset($_GET['email']) && !empty($_GET['email']) AND isset

($_GET['hash']) && !empty($_GET['hash'])){
                // Verify data
                $email = mysql_escape_string($_GET['email']); // Set email 

variable
                $hash = mysql_escape_string($_GET['hash']); // Set hash 

variable

                $search = mysql_query("SELECT email, Activation 

FROM gamesfx_members WHERE email='".$email."' AND Activation='".$hash."' AND active='0'") or die

(mysql_error()); 
                $match  = mysql_num_rows($search);

                if($match > 0){
                    // We have a match, activate the account
                    mysql_query("UPDATE gamesfx_members SET active='1' 

WHERE email='".$email."' AND Activation='".$hash."' AND active='0'") or die(mysql_error

());
                    echo '<div class="statusmsg">Your account has been 

activated, you can now login</div>';
                }else{
                    // No match -> invalid url or account has already 

been activated.
                    echo '<div class="statusmsg">The url is either 

invalid or you already have activated your account.</div>';
                }

            }else{
                // Invalid approach
                echo '<div class="statusmsg">Invalid approach, please use 

the link that has been send to your email.</div>';
            }

        ?>
        <!-- stop PHP Code -->


    </div>
    <!-- end wrap div -->   
</body>
</html>

如果有人可以请告诉我将值“活动”添加到数据库中的代码是什么,以便它可以与其他所有内容一起使用,请告诉我。另外..这是我当前的 table.sql 文件:

    --
-- Table structure for table `gamesfx_members`
--

CREATE TABLE IF NOT EXISTS `gamesfx_members` (
  `id` int(11) NOT NULL auto_increment,
  `usr` varchar(32) collate utf8_unicode_ci NOT NULL default '',
  `pass` varchar(32) collate utf8_unicode_ci NOT NULL default '',
  `email` varchar(255) collate utf8_unicode_ci NOT NULL default '',
  `Activation` varchar(40) DEFAULT NULL,
  `regIP` varchar(15) collate utf8_unicode_ci NOT NULL default '',
  `dt` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `usr` (`usr`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
4

1 回答 1

4
ALTER TABLE `gamesfx_members` ADD `active` integer;

MySql 文档

或者,如果您想重新创建表:

CREATE TABLE IF NOT EXISTS `gamesfx_members` (
  `id` int(11) NOT NULL auto_increment,
  `usr` varchar(32) collate utf8_unicode_ci NOT NULL default '',
  `pass` varchar(32) collate utf8_unicode_ci NOT NULL default '',
  `email` varchar(255) collate utf8_unicode_ci NOT NULL default '',
  `Activation` varchar(40) DEFAULT NULL,
  `regIP` varchar(15) collate utf8_unicode_ci NOT NULL default '',
  `dt` datetime NOT NULL default '0000-00-00 00:00:00',
  `active` integer NOT NULL default 0
  PRIMARY KEY  (`id`),
  UNIQUE KEY `usr` (`usr`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

另外,虽然这与您的问题没有直接关系,但请查看如何防止 PHP 中的 SQL 注入?有关如何在代码中编写更安全的数据库查询的信息。

于 2013-11-05T18:43:34.187 回答