hi
when edit link is clicked the form with the filled in fields will get displayed .the user the can edit the content in the fields and then when he clicks update the table will get updaed
here is my code...

here id is auto generating field in mysql
1st page
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");
$line = $_GET;

$result=mysql_query("SELECT * FROM table1 where id='$line'") or die("ERROR:".mysql_error());
for ($i = 0; $i < mysql_num_rows($result); ++$i)
{
$line = mysql_fetch_row($result);

print 'Name<input type="text" maxlength="19" size="53" name="name1" value="'.$line[0].'" />';

print '<input type="hidden" maxlength="19" size="53" name="name1" value="'.$line[0].'" />';
print '<input type="Submit" name="Submit" value="Submit" />';
}
2nd page

$name1=$_POST;
$id1=$_POST;
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");


if (isset($_REQUEST))
{
mysql_query("UPDATE table1 SET name='$name1' where id='$id1'") or die("ERROR:".mysql_error());
echo $name1;
echo $id1;
echo "THANKS FOR ENTERING UR DETAILS";
}

but the date is not getting updated

Recommended Answers

All 4 Replies

You are not passing $id from the previous page. Both has the name "name1".

Cheers.

sorry i did not get

print '<input type="hidden" maxlength="19" size="53" name="name1" value="'.$line[0].'" />';

This has to be

print '<input type="hidden" maxlength="19" size="53" name="id1" value="'.$line[0].'" />';

in page 1, because, in page2, ur trying to access $_POST[$id1] which never existed !

Oh, btw, you cant pass the data from 1page to another without using <form>. Try the following.

<?php  //page1.php
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");
$line = $_GET['id'];

$result=mysql_query("SELECT * FROM table1 where id='$line'") or die("ERROR:".mysql_error());
for ($i = 0; $i < mysql_num_rows($result); ++$i)
{
$line = mysql_fetch_row($result);
print '<form name="test" method="post" action="page2.php">';
print 'Name<input type="text" maxlength="19" size="53" name="name1" value="'.$line[0].'" />';

print '<input type="hidden" maxlength="19" size="53" name="id" value="'.$line[0].'" />';
print '<input type="Submit" name="Submit" value="Submit" />';
print '</form>';
}
?>

<?php  //page2.php
$name1=$_POST['name1'];
$id1=$_POST['id'];
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");


if (isset($_REQUEST['Submit']))
{
mysql_query("UPDATE table1 SET name='$name1' where id='$id1'") or die("ERROR:".mysql_error());
echo $name1;
echo $id1;
echo "THANKS FOR ENTERING UR DETAILS";
}
?>

I hope it helps.

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.