html problemo

Imaulle

[H]ard|Gawd
Joined
Jan 13, 2006
Messages
1,213
hihi,

can someone help fix this please?

this is for a button in my index.php page... Basically what I want is when I hit the 'update' button I want it to run update.php and then after that is done I want it to reload the index.php button

PHP:
<form action="update.php" method="post">
<button type="button">update</button>


this is probably really easy I'm just noob :(


thanks!!!
 
Code:
<form action="update.php" method="post">
<input type="submit" value="Update" />
</form>
 
hmm okay that works a little bit...

but after the update.php is done running it stays on update.php, I'd like it to go back to index.php after that is done? Is that possible without modifying update.php?
 
You're either going to have to change update.php to redirect back to index.php, or use AJAX. Here's how to do it with AJAX and the jQuery framework.

Code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
    $('#Button').click(function() {
        $.get('update.php', function(data) {
            location.reload();
        });
    });
});
</script>

<input id="Button" type="button" value="Update" />

That will make a GET request to update.php and when it's done, reload the page you're on. (index.php)
 
oh cool! that seems to work.

is there an easy way to add some animation gif or something so I know when its done? right now when I hit update it doesn't give any indication that it's "thinking" ya know?


thanks!!
 
okay new problem!

the script seems to interfere with the update.php code for some reason..

sometimes the NewUsedSlots is getting set to 0 when it should not be

here is the update.php

Code:
<?php
require_once('whm.php');
$mlink = @mysql_connect("localhost","username","password");
mysql_select_db("database", $mlink);
$result = mysql_query("SELECT * FROM ServerList");
while($row = mysql_fetch_array($result)){
  $server = new Whm;
  $server->init($row['HostName'],$row['UserName'],$row['PassHash']);
  $NewUsedSlots = count($server->listaccts());
  mysql_query("UPDATE ServerList SET UsedSlots='$NewUsedSlots' WHERE HostName='{$row['HostName']}'",$mlink);
}
?>
 
Why not just do the update.php stuff at the begining of the index.php page within a conditional?

Then you don't have to mess with the ajax/jquery stuff or redirects.
 
I'm with Gary on this one. Utilize server-side actions whenever possible and use JavaScript to fill any holes in the user experience (and try to avoid making actions reliant on JS). You can never be sure if a user is going to have JavaScript disabled or blocked or what have you.
 
I have a cron set to run update.php four times a day and I have no idea how I would add it into the index.php and have the cron still run? I'm sure it's possible but I'm not that skilled with PHP yet :(
 
I was actually able to get the jquery stuff to work.. everyone that is going to be using this script uses chrome so not too worried about any issues like that..

thanks for the help everyone
 
Back
Top