hi...........
my update code is working correcty.... .....but i want update links in front of every record of table ... plz tell me how it is possible...........
thanx for last reply..... m pretty new in php

[file name=updaterecord.php]

<?

$con=mysql_connect('localhost','root','root');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 mysql_select_db("test", $con);

// ***** This part will process when you Click on "Submit" button *****
// Check, if you clicked "Submit" button
if($_POST['Submit']){

// Get parameters from form.
$FirstName=$_POST['FirstName'];
$LastName=$_POST['LastName'];
$Age=$_POST['Age'];
//$tel=$_POST['tel'];

// Do update statement.
mysql_query("update student set FirstName='$FirstName', LastName='$LastName', Age='$Age' where FirstName='$FirstName'");

// Re-direct this page to select.php.
header("location:select1.php");
exit;
}
$FirstName=$_GET['FirstName'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from student where FirstName='$FirstName'");

// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);

// Close database connection.
mysql_close($con);
?>

<!-- END OF PHP CODES AND START HTML TAGS -->

<html>
<body>
<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form  name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<p>FirstName :
<input name="FirstName" type="text"  value="<? echo $row['FirstName']; ?>"/>
<br />
Last Name :
<!-- name of this text field is "email" -->
<input name="LastName" type="text"  value="<? echo $row['LastName']; ?>"/>
<br />
Age :
<!-- name of this text field is "tel" -->
<input name="Age" type="text"  value="<? echo $row['Age']; ?>"/>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
//select.php

<html>
<body bgcolor="pink">
<?
$con=mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 mysql_select_db("test", $con);
 $result=mysql_query("select * from student");
 echo "<table border='3'>   <BR><BR><BR><BR>
<tr>
<th >Firstname</th>
<th>Lastname</th>
<th> Age</th>
</tr>"  ;

 while($row=mysql_fetch_assoc($result))
 {
 echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['Age']. "</td>";
  echo "</tr>";



echo '<a href="updatecode.php?FirstName='.$row['FirstName'].' ">Update</a> ' ;


}
mysql_close($con);
?>
 </body></html>

Recommended Answers

All 4 Replies

hi...........
my update code is working correcty.... .....but i want update links in front of every record of table ... plz tell me how it is possible...........
thanx for last reply..... m pretty new in php

[file name=updaterecord.php]

<?

$con=mysql_connect('localhost','root','root');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 mysql_select_db("test", $con);

// ***** This part will process when you Click on "Submit" button *****
// Check, if you clicked "Submit" button
if($_POST['Submit']){

// Get parameters from form.
$FirstName=$_POST['FirstName'];
$LastName=$_POST['LastName'];
$Age=$_POST['Age'];
//$tel=$_POST['tel'];

// Do update statement.
mysql_query("update student set FirstName='$FirstName', LastName='$LastName', Age='$Age' where FirstName='$FirstName'");

// Re-direct this page to select.php.
header("location:select1.php");
exit;
}
$FirstName=$_GET['FirstName'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from student where FirstName='$FirstName'");

// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);

// Close database connection.
mysql_close($con);
?>

<!-- END OF PHP CODES AND START HTML TAGS -->

<html>
<body>
<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form  name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<p>FirstName :
<input name="FirstName" type="text"  value="<? echo $row['FirstName']; ?>"/>
<br />
Last Name :
<!-- name of this text field is "email" -->
<input name="LastName" type="text"  value="<? echo $row['LastName']; ?>"/>
<br />
Age :
<!-- name of this text field is "tel" -->
<input name="Age" type="text"  value="<? echo $row['Age']; ?>"/>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
//select.php

<html>
<body bgcolor="pink">
<?
$con=mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 mysql_select_db("test", $con);
 $result=mysql_query("select * from student");
 echo "<table border='3'>   <BR><BR><BR><BR>
<tr>
<th >Firstname</th>
<th>Lastname</th>
<th> Age</th>
</tr>"  ;

 while($row=mysql_fetch_assoc($result))
 {
 echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['Age']. "</td>";
  echo "</tr>";



echo '<a href="updatecode.php?FirstName='.$row['FirstName'].' ">Update</a> ' ;


}
mysql_close($con);
?>
 </body></html>

Well i think i know what your problem is on the "update" link. You have:
echo '<a href="updatecode.php?FirstName='.$row.' ">Update</a> ' ;

when it should be
$id = $row;
echo "<a href='updatecode.php?id=$id'>Update</a>";

This way when they click on the "update" link, it uses there ID instead of first name, which in the long run could cause problems.
Oh yeah, dont forget to change it on the first code block (line 29 and 32).

hiiiiiiiiiiiiiiiiiiiiiii
still m facing the same prob.ur suggesstion does nt work out.....

Try this code....

//select.php

<html>
<body bgcolor="pink">
<?

	$con=mysql_connect("localhost","root","root");
	if (!$con)
	  {
		die('Could not connect: ' . mysql_error());
	  }
	 mysql_select_db("test", $con);
	 $result=mysql_query("select * from student");
	  
	 echo "<table border='3'>
	  
			<tr>
				<th >Firstname</th>
				<th>Lastname</th>
				<th> Age</th>
				<th>Update</th>
			</tr>";

	 if(mysql_num_rows($result) > 0)
	{
		 while($row=mysql_fetch_assoc($result))
		 {
			 
			echo "<tr>";
				echo "<td>" . $row['FirstName'] . "</td>";
				echo "<td>" . $row['LastName'] . "</td>";
				echo "<td>" . $row['Age']. "</td>";
				echo '<td><a href="updatecode.php?id='.$row['id'].' ">Update</a></td> ' ;
				//Note : don't pass name as an identifier to update record, you must have to use id(primary key)
				//because more then one students can have same name.
			echo "</tr>";
			 
		 }
	}
	mysql_close($con);
?>
 </body>
	 
</html>

Thanxxx dr......... nw its workinng

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.