944,179 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 776
  • PHP RSS
Nov 29th, 2007
0

unable to update my table

Expand Post »
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<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['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
Similar Threads
Reputation Points: 3
Solved Threads: 2
Junior Poster
kings is offline Offline
107 posts
since Nov 2007
Nov 29th, 2007
0

Re: unable to update my table

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

Cheers.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Nov 29th, 2007
0

Re: unable to update my table

sorry i did not get
Reputation Points: 3
Solved Threads: 2
Junior Poster
kings is offline Offline
107 posts
since Nov 2007
Nov 29th, 2007
0

Re: unable to update my table

php Syntax (Toggle Plain Text)
  1. print '<input type="hidden" maxlength="19" size="53" name="name1" value="'.$line[0].'" />';
This has to be
php Syntax (Toggle Plain Text)
  1. 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 !
Last edited by nav33n; Nov 29th, 2007 at 8:22 am. Reason: Added more.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Nov 29th, 2007
0

Re: unable to update my table

Oh, btw, you cant pass the data from 1page to another without using <form>. Try the following.
php Syntax (Toggle Plain Text)
  1. <?php //page1.php
  2. $link=mysql_connect($hostname, $username, $password);
  3. mysql_select_db($dbid) or die("unable to connect");
  4. $line = $_GET['id'];
  5.  
  6. $result=mysql_query("SELECT * FROM table1 where id='$line'") or die("ERROR:".mysql_error());
  7. for ($i = 0; $i < mysql_num_rows($result); ++$i)
  8. {
  9. $line = mysql_fetch_row($result);
  10. print '<form name="test" method="post" action="page2.php">';
  11. print 'Name<input type="text" maxlength="19" size="53" name="name1" value="'.$line[0].'" />';
  12.  
  13. print '<input type="hidden" maxlength="19" size="53" name="id" value="'.$line[0].'" />';
  14. print '<input type="Submit" name="Submit" value="Submit" />';
  15. print '</form>';
  16. }
  17. ?>
  18.  
  19. <?php //page2.php
  20. $name1=$_POST['name1'];
  21. $id1=$_POST['id'];
  22. $link=mysql_connect($hostname, $username, $password);
  23. mysql_select_db($dbid) or die("unable to connect");
  24.  
  25.  
  26. if (isset($_REQUEST['Submit']))
  27. {
  28. mysql_query("UPDATE table1 SET name='$name1' where id='$id1'") or die("ERROR:".mysql_error());
  29. echo $name1;
  30. echo $id1;
  31. echo "THANKS FOR ENTERING UR DETAILS";
  32. }
  33. ?>

I hope it helps.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: oracle insert query failing + php
Next Thread in PHP Forum Timeline: .dco file from blob





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC