NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page how to display updated data after update?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 11-09-2008, 06:19 AM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Jan 2007
Posts: 98
baris22 is an unknown quantity at this point
 



how to display updated data after update?


hello all,

I am trying to lerarn how to update database. Everything is fine but after the update is done it is still showing the content which was before the update.

if i put the browser off and on again there is no problem, it is showing the updated content.

What can i do to show the updated content after pressing submit?

Thanks

PHP Code:

<?php
$host
="localhost"// Host name 
$username=""// Mysql username 
$password=""// Mysql password 
$db_name="test"// Database name 
$tbl_name="test_mysql"// Table name 

mysql_connect("$host""$username""$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
????: NamePros.com http://www.namepros.com/programming/531792-how-display-updated-data-after-update.html
<tr> 
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">


<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
????: NamePros.com http://www.namepros.com/showthread.php?t=531792
<td align="center"><input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>"></td>
<td align="center"><input name="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this 
if($Submit){
for(
$i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}

if(
$result1){
echo 
"<h4>Updated</h4>";
}
mysql_close();
?>
Ok sorted,


instead of

PHP Code:
echo "<h4>Updated</h4>"
i added

PHP Code:
echo "<meta http-equiv=\"refresh\" content=\"0\">"
__________________

Rapidme
(rapidshare application)
Last edited by baris22; 11-09-2008 at 08:02 AM.
baris22 is offline   Reply With Quote
Old 11-11-2008, 08:42 AM   #2 (permalink)
NamePros Regular
 
qbert220's Avatar
Join Date: Jul 2007
Location: UK
Posts: 394
qbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to behold
 


Protect Our Planet
I would move the update code to before the select query:

Code:
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Check if button name "Submit" is active, do this
if($Submit){
  for($i=0;$i<$count;$i++){
    $sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]' WHERE id='$id[$i]'";
    $result1=mysql_query($sql1);
  }
} 
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
qbert220 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:29 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger