954,219 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

unable to update my table

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['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 'Name';

print '';
print '';
}
2nd page

$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";
}

but the date is not getting updated

kings
Junior Poster
107 posts since Nov 2007
Reputation Points: 3
Solved Threads: 2
 

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

Cheers.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

sorry i did not get

kings
Junior Poster
107 posts since Nov 2007
Reputation Points: 3
Solved Threads: 2
 
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 !

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

Oh, btw, you cant pass the data from 1page to another without using . 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.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You