I am a php newbie.
I am doing a sports site, and trying to get the team name to display in an admin area.
I have tried the code below and many variations of it, however it continues to error the message :
Notice: Undefined index: team in ... on line 45

Why is this happening? I have a column in the admin table set up as team, so I am lost to what I have done wrong.

All I want to do is set the team name in the variable $teamName, so I can call to it on the pages needed.

$username = $_POST['username'];
$sql = "SELECT team FROM admin WHERE username='$username'";
$pds = $conn->prepare($sql);
$teamName = $_POST['team'];

Thanks for your help.



7 Years
Discussion Span
Last Post by colweb

Don't know what $conn->prepare and $pds->execute are supposed to do, but if you want to get a team from your database the following code might be helpfull. It doesn't check for errors (can't connect or anything like that).

$username = $_POST['username'];
$teamname = $_POST['team']; // but why is this needed if you select the team from the database

$sql = "SELECT team FROM admin WHERE username='$username'";
$pds = $conn->query($sql); // assuming $conn is new mysqli(hostname,username,password,database);
$num_results = $result->num_rows; // see how many results we get

if ($num_results == 1) { // 1 result
	$row = $result->fetch_assoc();
	echo "<p>Result of query: ".$row['team']."</p>";
else { // we have more results
	echo "<p>Result of query:<br>";
	for ($i=0; $i < $num_results; $i++) {
		$row = $result->fetch_assoc();
		echo $row['team']."<br>";
	echo "</p>";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.