Undefined index: id

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Vilash
Forum Commoner
Posts: 28
Joined: Tue Feb 07, 2012 1:24 am

Undefined index: id

Post by Vilash »

Hi, i am new to php,have created a login page which s working properly. But m getting undefined index error in admin login page.The code s below.
Getting error in
(<td><a href="member_display1.php?Id=<?php echo $row['Id'] ?>"><?php echo $row['Name']; ?></a></td>)

<!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>Untitled Document</title>
</head>

<body>
<?php
$con = mysql_connect("localhost", "login", "login123" );
if(!$con)
{
die('Could not connect:' . mysql_error());
}
mysql_select_db("test",$con);

$result = mysql_query(" SELECT Date,Name,Email,Phone FROM members1 ");

?>
<table width="100%" border="1" >
<tr>

<th>Date</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>

</tr>

<?php

$id=$_GET['id'];
while($row = mysql_fetch_array($result))
{

?><tr>

<td bgcolor="#FFFFFF"><?php echo $row['Date']; ?></td>

<td><a href="member_display1.php?Id=<?php echo $row['Id'] ?>"><?php echo $row['Name']; ?></a></td>

<td><?php echo $row['Email']; ?></td>

<td><?php echo $row['Phone']; ?></td>
<?php } ?>

</tr>
</table>


</body>
</html>

If anybody can troubleshoot please revert me as soon as possible..
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Undefined index: id

Post by social_experiment »

Code: Select all

<?php $result = mysql_query(" SELECT Date,Name,Email,Phone FROM members1 "); ?>
You don't select id from the database but you want to use it here <?php echo $row['Id'] ?>; Modify the query and the problem should disappear
Hth
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Vilash
Forum Commoner
Posts: 28
Joined: Tue Feb 07, 2012 1:24 am

Re: Undefined index: id

Post by Vilash »

How can i modify it...
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Undefined index: id

Post by social_experiment »

Assuming you have an id column in the database the query below should remedy the problem

Code: Select all

<?php $result = mysql_query(" SELECT Id, Date,Name,Email,Phone FROM members1 "); ?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Vilash
Forum Commoner
Posts: 28
Joined: Tue Feb 07, 2012 1:24 am

Re: Undefined index: id

Post by Vilash »

i did this bt its nt working... i wanted to display the registered members and if i click the names of the registered members it should display their details...i wanted to give link to their names through their id.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Undefined index: id

Post by social_experiment »

Are you still receiving the error? What fields do you have in your database and which one contains a value unique to each user
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Vilash
Forum Commoner
Posts: 28
Joined: Tue Feb 07, 2012 1:24 am

Re: Undefined index: id

Post by Vilash »

ya i am still getting error, i have id,name,email,phone,company,profession,city ,country,zip,comments,username,password,date.
id s primary key
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Undefined index: id

Post by social_experiment »

Paste the error here please; the error is really a notice and it indicates a variable that is not set. Have a look at the results of your query, see if the id value is passed along
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Vilash
Forum Commoner
Posts: 28
Joined: Tue Feb 07, 2012 1:24 am

Re: Undefined index: id

Post by Vilash »

Notice: Undefined index: id in C:\wamp\www\Extra\login9\member_display.php on line 41


this s the error m getting...
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Undefined index: id

Post by social_experiment »

This checks if the value is set; if it is it will echo the value to the browser; it should fix the notice you are getting; Does the value of $row['id'] display at all?

Code: Select all

<?php if isset($row['id']) echo $row['id']; ?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Vilash
Forum Commoner
Posts: 28
Joined: Tue Feb 07, 2012 1:24 am

Re: Undefined index: id

Post by Vilash »

ya the value of $row['id'] is displaying.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Undefined index: id

Post by social_experiment »

And the notice?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Vilash
Forum Commoner
Posts: 28
Joined: Tue Feb 07, 2012 1:24 am

Re: Undefined index: id

Post by Vilash »

notice s still there...where should i include the this php script <?php if isset($row['id']) echo $row['id']; ?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Undefined index: id

Post by social_experiment »

Assuming this is line 41 you can modify like the code below

Code: Select all

<td><a href="member_display1.php?Id=<?php if isset($row['Id']) echo $row['Id']; ?>"><?php echo $row['Name']; ?></a></td>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Vilash
Forum Commoner
Posts: 28
Joined: Tue Feb 07, 2012 1:24 am

Re: Undefined index: id

Post by Vilash »

nw the link is working...bt if i click on the link i displays only the header nt the contents ...
Id :
Name:
Email :
Phone :
Company :
Profession:
City :
Country:
Zip :
Comments:

Username:

Password:
Date:
Post Reply