PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,398 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,609 people online right now. Registration is fast and FREE... Join Now!




Refreshing Pages ( resolved )

 

Refreshing Pages ( resolved ), Resolved

peter yianni

2 Jul, 2009 - 11:46 AM
Post #1

D.I.C Regular
***

Joined: 4 Jun, 2009
Posts: 308



Thanked: 2 times
My Contributions
quick question i have pages that rename and delete they all work ok u call from the dropdown box and u can rename the (?)
that all works fine but i have to refresh the page before the new name shows is there a way to refresh results once u click rename

? Not important just wanted to make site a little better

heres the code

CODE
<?php require_once('../Connections/stablemaster.php');


session_start();

mysql_select_db($database_stablemaster, $stablemaster);
$stable_nameQ = mysql_query("SELECT stable_name FROM users WHERE id='".$_SESSION['uid']."'");
$stable_nameA = mysql_fetch_assoc($stable_nameQ);
$query_Recordset1 = "SELECT horse_stats.name_id FROM horse_stats WHERE `stable_name` = '".$stable_nameA['stable_name']."';";
$Recordset1 = mysql_query($query_Recordset1, $stablemaster) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$id = $_POST['horse'];$newname = $_POST['buy_horse_name'];$str = "UPDATE horse_stats SET name_id='$newname' WHERE name_id='$id'";mysql_query($str)or die(mysql_error());

?>
<style type="text/css">
<!--
body {
    background-color: #BFEBFF;
}
-->
</style><form action="<?php echo $_SERVER['PHP_SELF'];?>"
method="post" name="form1" id="form1">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="39%"><div align="center">
  <h4>Select Horse</h4>
</div></td>
<td width="61%"><select name="horse" id="horse">
<option value="" <?php if (!(strcmp("", $row_Recordset1['name_id']))) {echo "selected=\"selected\"";} ?>>select horse</option>
<?php
do {
?>
<option value="<?php echo $row_Recordset1['name_id']?>"<?php if (!(strcmp($row_Recordset1['name_id'], $row_Recordset1['name_id']))) {echo "selected=\"selected\"";} ?>><?php echo $row_Recordset1['name_id']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select></td>
</tr>
<tr>
<td><div align="center">
  <h4>Type in NewName Here </h4>
</div></td>
<td><input name="buy_horse_name" type="text" size="30" maxlength="25" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="rename Horse" id="rename Horse" value="rename " /></td>
</tr>
</table>
</form>
<p>&nbsp;</p>

</body>
</html>
<?php
mysql_free_result($Recordset1);

?>


This post has been edited by peter yianni: 2 Jul, 2009 - 07:37 PM

User is offlineProfile CardPM
+Quote Post


DecafJava

RE: Refreshing Pages ( Resolved )

2 Jul, 2009 - 12:13 PM
Post #2

New D.I.C Head
*

Joined: 18 May, 2009
Posts: 47


My Contributions
Just call this:

CODE

header('refresh: 5; url=http://www.yahoo.com' );


each time you want to refresh the page (for url, you can even put the same url as the current page so the content can refresh, and the 5 is the amount of seconds you want it to wait before refreshing...you can set it to anything).

This post has been edited by DecafJava: 2 Jul, 2009 - 12:14 PM
User is offlineProfile CardPM
+Quote Post

CTphpnwb

RE: Refreshing Pages ( Resolved )

2 Jul, 2009 - 02:04 PM
Post #3

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,065



Thanked: 151 times
Dream Kudos: 100
Expert In: PHP

My Contributions
Rather than refresh the page, you might put this:
CODE
$id = $_POST['horse'];$newname = $_POST['buy_horse_name'];$str = "UPDATE horse_stats SET name_id='$newname' WHERE name_id='$id'";mysql_query($str)or die(mysql_error());

at the beginning, but make it conditional so that if nothing has been posted, the query doesn't get run. This way, if a name change is submitted, it gets done before the recordsets are read, which should cause everything to show up correctly without needing to refresh.


User is offlineProfile CardPM
+Quote Post

peter yianni

RE: Refreshing Pages ( Resolved )

2 Jul, 2009 - 07:36 PM
Post #4

D.I.C Regular
***

Joined: 4 Jun, 2009
Posts: 308



Thanked: 2 times
My Contributions
QUOTE(CTphpnwb @ 2 Jul, 2009 - 02:04 PM) *

Rather than refresh the page, you might put this:
CODE
$id = $_POST['horse'];$newname = $_POST['buy_horse_name'];$str = "UPDATE horse_stats SET name_id='$newname' WHERE name_id='$id'";mysql_query($str)or die(mysql_error());

at the beginning, but make it conditional so that if nothing has been posted, the query doesn't get run. This way, if a name change is submitted, it gets done before the recordsets are read, which should cause everything to show up correctly without needing to refresh.



thanks u again all done
User is offlineProfile CardPM
+Quote Post

CTphpnwb

RE: Refreshing Pages ( Resolved )

3 Jul, 2009 - 05:09 AM
Post #5

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,065



Thanked: 151 times
Dream Kudos: 100
Expert In: PHP

My Contributions
By the way, you need to add some security measures. It's not a good idea to pass posted data to a query without at least running mysql_real_escape_string on it.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 10:11PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month