我一直试图在xampp上实现以下购物车网站。该页面的链接为:http://www.w3programmers.com/build-a-shopping-cart-with-php-part-1/
但是,当我尝试运行登录页面时,出现以下错误:-
以下是我尝试登录时打开的标签:
这是登录代码:-
<?php
session_start();
require("config.php");
if(isset($_SESSION['SESS_LOGGEDIN']) == TRUE) {
header("Location:".$config_basedir);
}
if($_POST['submit'])
{
$loginsql = "SELECT * FROM logins WHERE username = '" . $_POST['userBox']. "' AND password = '" . $_POST['passBox'] . "'";
$loginres = mysql_query($loginsql);
$numrows = mysql_num_rows($loginres);
if($numrows == 1)
{
$loginrow = mysql_fetch_assoc($loginres);
session_register("SESS_LOGGEDIN");
session_register("SESS_USERNAME");
session_register("SESS_USERID");
$_SESSION['SESS_LOGGEDIN'] = 1;
$_SESSION['SESS_USERNAME'] = $loginrow['username'];
$_SESSION['SESS_USERID'] = $loginrow['id'];
$ordersql = "SELECT id FROM rides WHERE customer_id = " . $_SESSION['SESS_USERID'] . " AND status < 2";
$orderres = mysql_query($ordersql);
$orderrow = mysql_fetch_assoc($orderres);
session_register("SESS_ORDERNUM"); $_SESSION['SESS_ORDERNUM'] = $orderrow['id'];
header("Location:".$config_basedir);
}
else {
header("Location:http://" .$_SERVER['HTTP_HOST']. $_SERVER['SCRIPT_NAME'] . "?error=1");
}
}
else {
require("header.php");
?>
<h1>Customer Login</h1>
Please enter your username and password to log into the websites. If you do not have an account, you can get one for free by <a href="register.php">registering</a>.
<?php
if(isset($_GET['error'])) {
echo "<strong>Incorrect username/password</strong>";
}
?>
<form action="<?php $_SERVER['SCRIPT_NAME']; ?><br />" method="POST">
<table>
<tbody>
<tr>
<td>Username</td>
<td><input type="textbox" name="userBox" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="passBox" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Log in" /></td>
</tr>
</tbody>
</table>
</form>
<?php
}
require("footer.php");
?>
这是标题代码:-
<?php
session_start();
if(isset($_SESSION['SESS_CHANGEID'])==TRUE){
session_unset();
session_regenerate_id();
}
require("config.php");
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
?>
<head>
<title><?php echo $config_sitename; ?></title>
<meta charset="utf-8"/>
<link rel="stylesheet" type="text/css" href="../stylesheet.css">
</head>
<body>
<div id="header">
<h1><?php echo $config_sitename; ?></h1>
</div>
<div id="menu">
<a href="<?php echo $congif_basedir; ?>">Home</a>
<a href="<?php echo $congif_basedir; ?>">View Rides</a>
</div>
<div id="container">
<div id="bar">
<?php
require("bar.php");
echo "<hr>";
if(isset($_SESSION['SESS_LOGGEDIN'])==True){
echo "Logged in as <strong>".$_SESSION['SESS_USERNAME']."</strong>[<a href='".$congif_basedir."logout.php'>logout</a>]";
}else{
echo "<a href='".$config_basedir."login.php'>Login</a>";
}
?>
</div>
<div id="main">
我不确定这与标头功能有关,尽管我不确定。
答案 0 :(得分:0)
我可以请您将config.php中的代码放到这里吗?或者至少告诉$ config_basedir什么值?
已更新:$config_basedir
应该是以下格式的URL:http://localhost/ . 'some folders' . 'file name with extension'
,例如:http://localhost/sites/shop/index.php
。
如果文件或文件的文件夹位于相同或子目录中,则您的URL可以是:文件'file_name
或folder/file_name
。例如index.php
或folder/folder/index.php
。
取决于您的服务器设置,诸如.php | .html
之类的扩展名可能不是必需的。也就是说,您可以像这样指示URL:folder/index
或index
; “索引”-在这种情况下是文件名。