unable to update my table

Reply

Join Date: Nov 2007
Posts: 107
Reputation: kings has a little shameless behaviour in the past 
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster

unable to update my table

 
0
  #1
Nov 29th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: unable to update my table

 
0
  #2
Nov 29th, 2007
You are not passing $id from the previous page. Both has the name "name1".

Cheers.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 107
Reputation: kings has a little shameless behaviour in the past 
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster

Re: unable to update my table

 
0
  #3
Nov 29th, 2007
sorry i did not get
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: unable to update my table

 
0
  #4
Nov 29th, 2007
  1. print '<input type="hidden" maxlength="19" size="53" name="name1" value="'.$line[0].'" />';
This has to be
  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.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: unable to update my table

 
0
  #5
Nov 29th, 2007
Oh, btw, you cant pass the data from 1page to another without using <form>. Try the following.
  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.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC