注意:第3行C:\xampp\htdocs\gpt\includes.php中的未定义索引:username

注意:第3行C:\xampp\htdocs\gpt\includes.php中的未定义索引:username,php,mysql,xampp,Php,Mysql,Xampp,当涉及到PHP和其他开发工具时,我是一个noob。不管怎样,从过去两天以来,我一直在努力寻找解决办法。我几乎到处找。因此,我试图使用XAMPP将设计集成到GPT脚本中,但每次尝试转到文件所在的localhost/GPT时,都会出现一系列错误。页面顶部显示以下内容:- "; }}}} if(isset($_SESSION['username']) && isset($_SESSION['password'])){ header("Location: members.php"); }

当涉及到PHP和其他开发工具时,我是一个noob。不管怎样,从过去两天以来,我一直在努力寻找解决办法。我几乎到处找。因此,我试图使用XAMPP将设计集成到GPT脚本中,但每次尝试转到文件所在的localhost/GPT时,都会出现一系列错误。页面顶部显示以下内容:-

"; }}}} if(isset($_SESSION['username']) && isset($_SESSION['password'])){ header("Location: members.php"); } ?>
Notice: Undefined index: username in C:\xampp\htdocs\gpt\includes.php on line 3

Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\xampp\htdocs\gpt\includes.php on line 3

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\gpt\includes.php on line 3

Notice: Trying to get property of non-object in C:\xampp\htdocs\gpt\includes.php on line 9

Notice: Trying to get property of non-object in C:\xampp\htdocs\gpt\includes.php on line 14

Notice: Trying to get property of non-object in C:\xampp\htdocs\gpt\includes.php on line 15

Notice: Trying to get property of non-object in C:\xampp\htdocs\gpt\includes.php on line 16
我尝试添加
错误报告(E_ALL^E_NOTICE)
到config.php和includes.php的顶部,然后错误减少为:-

"; }}}} if(isset($_SESSION['username']) && isset($_SESSION['password'])){ header("Location: members.php"); } ?>
Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\xampp\htdocs\gpt\includes.php on line 4

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\gpt\includes.php on line 4
我还尝试添加了
session_start()到每个页面。
无论如何,这些都是涉及到的页面:-

config.php

<?
session_start();ob_start();
$hostname = "localhost"; //your hostname (normally localhost)
$data_username = "root"; //database username
$data_password = ""; //database password
$data_basename = "gpt"; //database name
$conn = mysql_connect("".$hostname."","".$data_username."","".$data_password."");  
mysql_select_db("".$data_basename."") or die(mysql_error());  
$bonuspoints=10; //bonus points awarded for new users
$mainpointsneeded=200; //max number of points needed before user can request voucher
?>

includes.php

<?php 
error_reporting (E_ALL ^ E_NOTICE); 
session_start();
$fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE username='".$_SESSION['username']."'"));
$title= "My Voucher Geek";  //your site title
$yourdomain="http://localhost/gpt"; //your domain name where script is installed - do not use trailing slash
$tweetmsg="Get Amazon and ASOS gift vouchers for free at http://www.myvouchergeek.com"; //set text for tweet this button on homepage
$bonuspoints= 10;    //amount of bonus points to give to users
$refer_points=2; //amount of points a user receives if one of their referred users completes any survey
$ref_id=$fetch_users_data->id;
if(isset($_GET['join'])){
    $referral_ID = $_GET['join'];
    $referral_string= "?join=".$referral_ID;
}
$membername= $fetch_users_data->username; //don't change
$memberpoints=$fetch_users_data->points; //don't change
$membersurveys=$fetch_users_data->completed_surveys; //don't change
$earnedpoints = $memberpoints - $bonuspoints;//if you want to display how many points user has earned (as opposed to bonus points)
$mainpointsneeded = 200; //total points needed before user can request a voucher
$pointsneeded= $mainpointsneeded - $memberpoints; //points left before they can request voucher
$contactemail = "YOUR_EMAIL_ADDRESS"; //contact form messages will be sent here
$requestemail = "THE_SAME_OR_ANOTHER_EMAIL_ADDRESS"; //request a voucher messages will be sent here
?>

这些都是警告,所有的
mysql.*
函数都已弃用,您不应该再使用它们了。如果不想显示警告,则需要在使用这些功能之前移动错误报告设置。现在您有
错误报告(E_ALL ^E_通知)includes.php
顶部的code>是最后一个被调用的对象。您应该将其移动到
config.php
的顶部。此外,使用您现在的错误设置,您将显示除通知之外的所有错误,因此警告仍将显示。如果要隐藏警告和/或不推荐的错误条目,需要将其更改为:

error_reporting(E_ERROR);
您还应该更改这些行,您不需要引号:

//$conn = mysql_connect("".$hostname."","".$data_username."","".$data_password."");
//mysql_select_db("".$data_basename."") or die(mysql_error());
$conn = mysql_connect($hostname,$data_username,$data_password);
mysql_select_db($data_basename) or die(mysql_error());
而且现在你的脚本非常不安全<代码>$username
在发送到数据库之前不会被过滤


你还有其他地方有
$variable1=“”.$variable2。“
这些双引号你有一个一文不值的。你可以说
$variable=$variable2

在我看来,您的
short\u open\u标签已禁用,而我第一次尝试了该功能。没用。说清楚,去掉所有短标签
谢谢,先生。根据你的建议,一些问题已经解决了,比如我现在可以使用测试帐户登录。我是个笨蛋,请试着理解。你能告诉我如何解决“MySQL不推荐使用”的问题吗。因为这似乎是主要问题,谢谢你的评论。但是,我不想隐藏错误。实际上,我希望整个脚本在XAMPP上工作,因为它在上传到网站主机时工作。我在托管帐户上尝试过这个脚本,在那里效果很好。我对XAMPP没有太多经验。那么,如果我向某人提供脚本,他们能在theri XAMPP上检查并修复错误吗?如果不反对TOS,如果有人愿意帮忙,如果你想修复脚本,你首先要做的就是去掉所有的
mysql.*
函数。像
mysql\u connect
mysql\u select\u db
mysql\u query
,等等……还有什么可以替代它们,因为这些是脚本正常运行所必需的。我想问题暂时解决了。实际上,正如通知所说,我添加了“改用mysqli或PDO”
//$conn = mysql_connect("".$hostname."","".$data_username."","".$data_password."");
//mysql_select_db("".$data_basename."") or die(mysql_error());
$conn = mysql_connect($hostname,$data_username,$data_password);
mysql_select_db($data_basename) or die(mysql_error());