gpt4 book ai didi

php - 用户名已被使用

转载 作者:行者123 更新时间:2023-11-29 08:18:03 26 4
gpt4 key购买 nike

好的,我希望有人可以帮助我。 首先我想说,我并不是在要求代码只是在我与数据库的连接问题上提供一些帮助。

我的网站的所有文件都位于运行 Windows 7 的 wamp 服务器的 www 目录中。 www 目录是本地主机,我们大多数人都知道,我的 table.sql 文件以及我网站的 php 文件都位于该目录中。

我的问题是我在 phpmyadmin 上加载了 table.sql 并测试了 sql 文件,当我去注册时它如何工作,它说“此用户名已被占用!”尽管数据库中没有任何内容......奇怪正确的?

我已经尝试了好几天让它正常工作,我从我的网站上发布了一些代码,看看这里是否有人可以指出错误,以便我可以纠正它。

注意:网站本身工作正常,但在尝试注册和登录时遇到问题。

最后一个问题,我是否必须在 connect.php 文件或 myphpadmin 上拥有 mysql 的 usr 和密码?

这是主页的源代码或标记。 “演示.php”

<?php

define('INCLUDE_CHECK',true);

require 'connect.php';
require 'functions.php';
// Those two files can be included only if INCLUDE_CHECK is defined


session_name('tzLogin');
// Starting the session

session_set_cookie_params(2*7*24*60*60);
// Making the cookie live for 2 weeks

session_start();

if($_SESSION['id'] && !isset($_COOKIE['tzRemember']) && !$_SESSION['rememberMe'])
{
// If you are logged in, but you don't have the tzRemember cookie (browser restart)
// and you have not checked the rememberMe checkbox:

$_SESSION = array();
session_destroy();

// Destroy the session
}


if(isset($_GET['logoff']))
{
$_SESSION = array();
session_destroy();

header("Location: demo.php");
exit;
}

if($_POST['submit']=='Login')
{
// Checking whether the Login form has been submitted

$err = array();
// Will hold our errors


if(!$_POST['username'] || !$_POST['password'])
$err[] = 'All the fields must be filled in!';

if(!count($err))
{
$_POST['username'] = mysql_real_escape_string($_POST['username']);
$_POST['password'] = mysql_real_escape_string($_POST['password']);
$_POST['rememberMe'] = (int)$_POST['rememberMe'];

// Escaping all input data

$row = mysql_fetch_assoc(mysql_query("SELECT id,usr FROM tz_members WHERE usr='{$_POST['username']}' AND pass='".md5($_POST['password'])."'"));

if($row['usr'])
{
// If everything is OK login

$_SESSION['usr']=$row['usr'];
$_SESSION['id'] = $row['id'];
$_SESSION['rememberMe'] = $_POST['rememberMe'];

// Store some data in the session

setcookie('tzRemember',$_POST['rememberMe']);
}
else $err[]='Wrong username and/or password!';
}

if($err)
$_SESSION['msg']['login-err'] = implode('<br />',$err);
// Save the error messages in the session

header("Location: demo.php");
exit;
}
else if($_POST['submit']=='Register')
{
// If the Register form has been submitted

$err = array();

if(strlen($_POST['username'])<4 || strlen($_POST['username'])>32)
{
$err[]='Your username must be between 3 and 32 characters!';
}

if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['username']))
{
$err[]='Your username contains invalid characters!';
}

if(!checkEmail($_POST['email']))
{
$err[]='Your email is not valid!';
}

if(!count($err))
{
// If there are no errors

$pass = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
// Generate a random password

$_POST['email'] = mysql_real_escape_string($_POST['email']);
$_POST['username'] = mysql_real_escape_string($_POST['username']);
// Escape the input data


mysql_query(" INSERT INTO tz_members(usr,pass,email,regIP,dt)
VALUES(

'".$_POST['username']."',
'".md5($pass)."',
'".$_POST['email']."',
'".$_SERVER['REMOTE_ADDR']."',
NOW()

)");

if(mysql_affected_rows($link)==1)
{
send_mail( 'demo-test@tutorialzine.com',
$_POST['email'],
'Registration System Demo - Your New Password',
'Your password is: '.$pass);

$_SESSION['msg']['reg-success']='We sent you an email with your new password!';
}
else $err[]='This username is already taken!';
}

if(count($err))
{
$_SESSION['msg']['reg-err'] = implode('<br />',$err);
}

header("Location: demo.php");
exit;
}

$script = '';

if($_SESSION['msg'])
{
// The script below shows the sliding panel on page load

$script = '
<script type="text/javascript">

$(function(){

$("div#panel").show();
$("#toggle a").toggle();
});

</script>';

}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to AZ Barter</title>

<link rel="stylesheet" type="text/css" href="demo.css" media="screen" />
<link rel="stylesheet" type="text/css" href="login_panel/css/slide.css" media="screen" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<!-- PNG FIX for IE6 -->
<!-- http://24ways.org/2007/supersleight-transparent-png-in-ie6 -->
<!--[if lte IE 6]>
<script type="text/javascript" src="login_panel/js/pngfix/supersleight-min.js"></script>
<![endif]-->

<script src="login_panel/js/slide.js" type="text/javascript"></script>

<?php echo $script; ?>
</head>


<body>

<!-- Panel -->
<div id="toppanel">
<div id="panel">
<div class="content clearfix">
<div class="left">
<h1>Welcome to AZ Barter</h1>
<h2>Register/login ====></h2>
<p class="grey"></p>

</div>


<?php

if(!$_SESSION['id']):

?>

<div class="left">
<!-- Login Form -->
<form class="clearfix" action="" method="post">
<h1>Member Login</h1>

<?php

if($_SESSION['msg']['login-err'])
{
echo '<div class="err">'.$_SESSION['msg']['login-err'].'</div>';
unset($_SESSION['msg']['login-err']);
}
?>

<label class="grey" for="username">Username:</label>
<input class="field" type="text" name="username" id="username" value="" size="23" />
<label class="grey" for="password">Password:</label>
<input class="field" type="password" name="password" id="password" size="23" />
<label><input name="rememberMe" id="rememberMe" type="checkbox" checked="checked" value="1" /> &nbsp;Remember me</label>
<div class="clear"></div>
<input type="submit" name="submit" value="Login" class="bt_login" />
</form>
</div>
<div class="left right">
<!-- Register Form -->
<form action="" method="post">
<h1>Not a member yet? Sign Up!</h1>

<?php

if($_SESSION['msg']['reg-err'])
{
echo '<div class="err">'.$_SESSION['msg']['reg-err'].'</div>';
unset($_SESSION['msg']['reg-err']);
}

if($_SESSION['msg']['reg-success'])
{
echo '<div class="success">'.$_SESSION['msg']['reg-success'].'</div>';
unset($_SESSION['msg']['reg-success']);
}
?>

<label class="grey" for="username">Username:</label>
<input class="field" type="text" name="username" id="username" value="" size="23" />
<label class="grey" for="email">Email:</label>
<input class="field" type="text" name="email" id="email" size="23" />
<label>A password will be e-mailed to you.</label>
<input type="submit" name="submit" value="Register" class="bt_register" />
</form>
</div>

<?php

else:

?>

<div class="left">

<h1>Members panel</h1>

<p>You can put member-only data here</p>
<a href="registered.php">View a special member page</a>
<p>- or -</p>
<a href="?logoff">Log off</a>

</div>

<div class="left right">
</div>

<?php
endif;
?>
</div>
</div> <!-- /login -->

<!-- The tab on top -->
<div class="tab">
<ul class="login">
<li class="left">&nbsp;</li>
<li>Hello <?php echo $_SESSION['usr'] ? $_SESSION['usr'] : 'Guest';?>!</li>
<li class="sep">|</li>
<li id="toggle">
<a id="open" class="open" href="#"><?php echo $_SESSION['id']?'Open Panel':'Log In | Register';?></a>
<a id="close" style="display: none;" class="close" href="#">Close Panel</a>
</li>
<li class="right">&nbsp;</li>
</ul>
</div> <!-- / top -->

</div> <!--panel -->


<div id="main_container">
<div id="header">
<div class="logo"><img src="images/az_barter.png" border="0" alt="" title="" /></div>
</div>
<div class="menu">
<ul>
<li class="selected"><a href="index.php">home</a></li>
</ul>
</div>

<div class="center_content">

<div class="center_left">
<div class="welcome_box">
<p class="welcome">
<span class="orange">Welcome to AZ BARTER !!! </span><br />
Here at AZ Barter we trade, buy, and sell anything from your ordinary house hold items to vehicles. I hope here at AZ Barter we have created a fun, secure and enjoyable way to purchase your favorite products. AZ Barter deals with trading, buying, and selling options via PAYPAL only.
</p>

</div>



<div class="features">
<div class="title">Latest News</div>
<div class="news_box">
<div class="news_icon"></div>
<div class="news_content">
You must be logged on to view products buy/sell and or trade , we apologize for the inconvenience.
</div>
</div>
<div class="news_box">
<div class="news_icon"></div>
<div class="news_content">
Posting your ads here will always be free of charge.
</div>
</div>

</div>





</div>


<div class="center_right">

<div class="software_box"><img src="images/computer.jpg" alt="" title="" /></div>





</div>

<div class="clear"></div>

</div>


<div id="footer">
<div class="left_footer"><a href="index.php">home</a><a href="policy.php">privacy policy</a><a href="contact.php">contact</a></div>

</div>

</div>



</div>
<!-- end of main_container -->

</body>
</html>

这是 connect.php 文件的代码

<?php

if(!defined('INCLUDE_CHECK')) die('You are not allowed to execute this file directly');


/* Database config */

$db_host = 'localhost';
$db_user = 'admin';
$db_pass = 'Shadowman80';
$db_database = 'table.sql';





/* End config */



$conn = mysql_connect($host,$username,$password) or die('Unable to establish a DB connection');

mysql_select_db($db_database,$conn);
mysql_query("SET names UTF8");

?>

这是 table.sql 文件的代码

--
-- Table structure for table `tz_members`
--

CREATE TABLE `tz_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 '',
`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;

我正在我的计算机上运行最新版本的 wamp。

最佳答案

您的数据库连接不正确。所以每次条件

if(mysql_affected_rows($link)==1)

变为 false,它会显示您可以看到的消息。

$db_host        = 'localhost';
$db_user = 'admin';
$db_pass = 'Shadowman80';
$db_database = '<databaseName>'; //Here it might cause issue

关于php - 用户名已被使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20170724/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com