Hi,
I'm fairly new to php and am having a lot of trouble with a simple little select problem. I have tried it about 20 different ways and it just keeps spitting out errors and not working
My code is:
<?php
session_start(); // built in php function to start the session array
require_once('../includes/admin/db.php'); // database connection
$conn = dbConnect('admin');
if(isset($_POST['login'])) {
$sql='SELECT * FROM admin WHERE username=? AND passwd=?';
$pds=$conn->prepare($sql);
$pds->execute(array($_POST['username'],(sha1($_POST['passwd']))));
if($pds->fetchColumn(0)) { // Success
$_SESSION['admin']=$_POST['username'];
}
else { // Failure
$error='<p>Unsuccessful Login</p>';
}
}
elseif(isset($_POST['logout'])) {
unset($_SESSION['admin']); // closes the admin session
setcookie(session_name(),'',time()-86400);
session_destroy();
}
--------
Line 27 $username = $_POST['username'];
$sql = 'SELECT team FROM users WHERE username = "$username"';
if (!$sql) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$teamName = mysql_fetch_row($sql);
All I want to do is make $teamName the name of the team that that user is editing. just can't figure out what I am doing wrong. All the code above the -------- works fine, but the stuff below is the problem.
the main error that I am having is: Notice: Undefined index: username in C:\Users\...\dash.php on line 27
It should be easy to do I thought, but I have spent about 12 hours trying different things with no luck.
Please help, if you could give me the code I should be using that would be awesome.
Thanks,
QWaz