MHaris
08-17-2007, 12:26 AM
<?php
// Last Modified 16th August
ob_start();
include('templates/header.php'); // Header template
include('../config/config.php'); // Includes configuration files
include('../lib/functions.php'); // Load all functions from Library
include('templates/login.php'); // Login form
$submit = $_POST['log_in'];
$posted_username = sql_safe($_POST['username']);
$posted_password = sql_safe($_POST['password']);
if(isset($submit)){
if($posted_username == $username && $posted_password == $password){
echo "Logged in";
$_SESSION["username"];
$_SESSION["password"];
}
else {
echo "Wrong username or password";
}
}
include('templates/footer.php'); // Footer Template
?>
Sessions are not registering for me. An example of sessions being used at are:
<?php
// Last Modified 14th August 2007
ob_start();
session_start(); // Loads session
include('templates/header.php'); // Header Template
include('../config/config.php'); // Includes configuration files
include('../lib/functions.php'); // Load all functions from Library
if(!isset($_SESSION["username"])){
header('Location: index.php');
exit();
}
else {
include('templates/candidates.php'); // Add new candidates template
$submit = $_POST['submit']; // Submit button
$candidate = sql_safe($_POST['name']); // New candidate's name
if(isset($submit)){
mysql_query("INSERT INTO candidates(name) VALUES('$candidate')") or die(mysql_error());
$newly_created_candidate = mysql_query("SELECT * FROM candidates ORDER BY `id` desc LIMIT 1");
while ($row = mysql_fetch_array($newly_created_candidate)){
$candidateID = $row['id'];
}
$result = mysql_query("SELECT id FROM questions");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$qid=$row[0];
$query = "INSERT INTO answers(answer,candidate_id,question_id) VALUES('1','$candidateID','$qid')";
mysql_query($query)or die(mysql_error());
}
}
$sql = mysql_query("SELECT * FROM candidates");
while($row = mysql_fetch_array($sql)){
echo $row['name'];
echo "<br />";
$count++;
}
echo '<br /><b>There are '. $count.' Candidates</b>';
mysql_close(); // Closes DB connection
}
include('templates/footer.php'); // Footer Template
?>
Any ideas, what am I doing wrong?
// Last Modified 16th August
ob_start();
include('templates/header.php'); // Header template
include('../config/config.php'); // Includes configuration files
include('../lib/functions.php'); // Load all functions from Library
include('templates/login.php'); // Login form
$submit = $_POST['log_in'];
$posted_username = sql_safe($_POST['username']);
$posted_password = sql_safe($_POST['password']);
if(isset($submit)){
if($posted_username == $username && $posted_password == $password){
echo "Logged in";
$_SESSION["username"];
$_SESSION["password"];
}
else {
echo "Wrong username or password";
}
}
include('templates/footer.php'); // Footer Template
?>
Sessions are not registering for me. An example of sessions being used at are:
<?php
// Last Modified 14th August 2007
ob_start();
session_start(); // Loads session
include('templates/header.php'); // Header Template
include('../config/config.php'); // Includes configuration files
include('../lib/functions.php'); // Load all functions from Library
if(!isset($_SESSION["username"])){
header('Location: index.php');
exit();
}
else {
include('templates/candidates.php'); // Add new candidates template
$submit = $_POST['submit']; // Submit button
$candidate = sql_safe($_POST['name']); // New candidate's name
if(isset($submit)){
mysql_query("INSERT INTO candidates(name) VALUES('$candidate')") or die(mysql_error());
$newly_created_candidate = mysql_query("SELECT * FROM candidates ORDER BY `id` desc LIMIT 1");
while ($row = mysql_fetch_array($newly_created_candidate)){
$candidateID = $row['id'];
}
$result = mysql_query("SELECT id FROM questions");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$qid=$row[0];
$query = "INSERT INTO answers(answer,candidate_id,question_id) VALUES('1','$candidateID','$qid')";
mysql_query($query)or die(mysql_error());
}
}
$sql = mysql_query("SELECT * FROM candidates");
while($row = mysql_fetch_array($sql)){
echo $row['name'];
echo "<br />";
$count++;
}
echo '<br /><b>There are '. $count.' Candidates</b>';
mysql_close(); // Closes DB connection
}
include('templates/footer.php'); // Footer Template
?>
Any ideas, what am I doing wrong?