PHP - Data updated on the same page without reloading

quostin

New Member
Messages
3
Reaction score
0
Points
0
I'm trying to show the same data, but updated right away. For example. I want to update my coords on a map and refresh a div to show the new data, but as the code now, it keeps the same data until I reload the page. Here is the code I have now.

PHP:
if ($north){$ylocation = $users['y'] + 1;if ($ylocation > 5){$ylocation = 0;}$locationyupdate = ("UPDATE players SET y = '$ylocation' WHERE name='$users[name]'");		mysql_query($locationyupdate) or die("could not register");?><script type="text/javascript">$('#npc').load('npc.php');$('#description').load('description.php');</script><?}

The update code is before the reload script for the two div's. The data DOES change in the script, but the two div's won't display the new data until it is refreshed again.

Do I need to reactivate fetch to get the new data?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Try reposting your script in a readable format.

And try rephrasing your question.

And maybe give us a URL to look at/test.
 

quostin

New Member
Messages
3
Reaction score
0
Points
0
http://quostin.x10.mx/clone/ is the site. You would have to register and login though.

When you click north, it refreshes the div on the left (with image and text and location) You will noticed that the location doesn't move, but if you click again, it will show the location move, but it would still be wrong by one. I want it to display the right data with one refresh on that div.

PHP:
if ($north)
{
$ylocation = $users['y'] + 1;
if ($ylocation > 5)
{
$ylocation = 0;
}
$locationyupdate = ("UPDATE players SET y = '$ylocation' WHERE name='$users[name]'");
mysql_query($locationyupdate) or die("could not register");
?>
<script type="text/javascript">
$('#npc').load('npc.php');
$('#description').load('description.php');
</script>
<?
}

The code update "y" into the database like it is told, but it isn't pulled right away and shows the old y data.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Partial code and no live page.

Bye.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Code samples should be complete, concise and representative; the issue must be reproducible. If there isn't a suitable page you can share, create a sample page.

Pick and apply an indent style to make your code more readable.

The mysql extension is outdated and on its way to deprecation. Instead, use PDO, which has many useful improvements, such as prepared statements and support for the Traversable interface, so you can loop over results with foreach. If you need a PDO tutorial, try "Writing MySQL Scripts with PHP and PDO".

Speaking of prepared statements, the sample may be vulnerable to [SQL injection](http://unixwiz.net/techtips/sql-injection.html), which is a very serious [security risk](http://bobby-tables.com/). Prepared statement parameters aren't vulnerable to injection, as they keep data and the statement separate.

Don't use die when outputting HTML. You'll get invalid HTML.
 
Top