Amruta
Amruta

Reputation: 9

PHP: passing parameters in the URL dynamically

I want to display data in database in table form. I wrote the following code

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['EmpID'] . "</td>";
echo "<td>" . $row['EmpName'] . "</td>";
echo "<td>" . $row['Designation'] . "</td>";
echo "<td>" . $row['Salary'] . "</td>";
echo "<td><a href='upasg3.php?empid='". $row['EmpID'] .">Edit</a ></td>";
echo "<td><a href='upasg3.php?empid='". $row['EmpID'] .">Delete</a ></td>"; 
echo "</tr>";
}

But i dont get the value of $row['EmpID'] concatenated with the value of href. It redirects to the upasg3.php with empid= blank. how to fix this? Please help

Upvotes: 1

Views: 794

Answers (5)

Sandy Fark
Sandy Fark

Reputation: 173

 <table width="100%" border="1">
  <tr>
 <td>ID</td>
<td>NAME</td>
<td>Designation</td>
<td>Salary</td>
<td>Edit</td>
  <td>Delete</td>
</tr>
<tr>
  <td><?=$row['EmpID']?></td>
<td><?=$row['EmpName']?></td>
<td><?=$row['Designation']?></td>
<td><?=$row['Salary']?></td>
<td><a href="upasg3.php?empid=<?=$row['EmpID']?>">Edit</a></td>
 <td><a href="upasg3.php?empid=<?=$row['EmpID']?>">Delete</a></td>
 </tr>

Upvotes: 1

itachi
itachi

Reputation: 6393

try this

echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Edit</a ></td>";
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Delete</a ></td>"; 

Your quotes were in wrong place.

Upvotes: -1

heyanshukla
heyanshukla

Reputation: 669

Try

echo "<td><a href='upasg3.php?empid=". $row['EmpID']."'>Edit</a ></td>";
                                    ^                 ^

Upvotes: 1

ShaaD
ShaaD

Reputation: 626

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['EmpID'] . "</td>";
echo "<td>" . $row['EmpName'] . "</td>";
echo "<td>" . $row['Designation'] . "</td>";
echo "<td>" . $row['Salary'] . "</td>";
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Edit</a ></td>";
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Delete</a ></td>"; 
echo "</tr>";
}

quotes.

Upvotes: 4

IsisCode
IsisCode

Reputation: 2490

Try removing the single quotes after empid=

And putting them here like this:

echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Edit</a ></td>";
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Delete</a ></td>"; 

This will give you an output like:

<a href='upasg3.php?empid=100'>

Upvotes: 2

Related Questions