Page 1 of 2

Undefined index: id

Posted: Tue Feb 07, 2012 1:56 am
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..

Re: Undefined index: id

Posted: Tue Feb 07, 2012 5:56 am
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

Re: Undefined index: id

Posted: Tue Feb 07, 2012 11:15 pm
by Vilash
How can i modify it...

Re: Undefined index: id

Posted: Tue Feb 07, 2012 11:19 pm
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 "); ?>

Re: Undefined index: id

Posted: Tue Feb 07, 2012 11:40 pm
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.

Re: Undefined index: id

Posted: Tue Feb 07, 2012 11:44 pm
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

Re: Undefined index: id

Posted: Wed Feb 08, 2012 12:00 am
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

Re: Undefined index: id

Posted: Wed Feb 08, 2012 12:12 am
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

Re: Undefined index: id

Posted: Wed Feb 08, 2012 12:22 am
by Vilash
Notice: Undefined index: id in C:\wamp\www\Extra\login9\member_display.php on line 41


this s the error m getting...

Re: Undefined index: id

Posted: Wed Feb 08, 2012 12:33 am
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']; ?>

Re: Undefined index: id

Posted: Wed Feb 08, 2012 12:50 am
by Vilash
ya the value of $row['id'] is displaying.

Re: Undefined index: id

Posted: Wed Feb 08, 2012 1:05 am
by social_experiment
And the notice?

Re: Undefined index: id

Posted: Wed Feb 08, 2012 1:24 am
by Vilash
notice s still there...where should i include the this php script <?php if isset($row['id']) echo $row['id']; ?>

Re: Undefined index: id

Posted: Wed Feb 08, 2012 1:29 am
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>

Re: Undefined index: id

Posted: Wed Feb 08, 2012 2:29 am
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: