...

View Full Version : submit button issue



CallumJohnson
05-03-2009, 05:40 PM
if ($username != 'mic4'){
if ($info->lastcrime > time()){
$timeleft = $info->lastcrime - time();
echo "<font color=\"white\"><center><br /><br /><strong>"
."$timeleft seconds before you can do another cime!</strong><br /><br /></center>";


if($session->isAdmin()){ //New bit
echo '<center><input name="resetadmin" id="resetadmin" type="submit" value="reset admin" /></center>'; }
//Function to show link to admin centre

exit(); }
}


Thats the submit button (its in the $session->admin if statement), when clicked i want it to execute this code only:


//New bit
if (strip_tags($_POST['resetadmin'])){

$reset_admin = strip_tags($_POST['resetadmin']);
mysql_query("UPDATE users SET lastcrime='0', WHERE username='$username'");
};//end new bit


I can't get it to execute the above code, a solution would be apreciated :)
I'm sure its me having a mental block :P

djm0219
05-03-2009, 05:57 PM
Where is the form statement and what code is it calling?

CallumJohnson
05-03-2009, 06:12 PM
Where is the form statement and what code is it calling?

I have to put the button in a form?

Damn i want to now create a new form statement and create a function to execute the bottom codebox code.

bdl
05-03-2009, 07:03 PM
I have to put the button in a form?

Damn i want to now create a new form statement and create a function to execute the bottom codebox code.

I know this wasn't meant to be funny, but I had a chuckle at your expense, I think. ;)

You technically don't have to wrap an INPUT or BUTTON in a FORM element, but it's not usable unless you use JavaScript / DOM code to make it work. Doing so would require everyone that uses your application to have JavaScript enabled or use a certain browser to ensure compatibility, and that's not likely.

CallumJohnson
05-03-2009, 07:05 PM
ahhhh, how does one direct a form's action"" tag to a specific function?

CallumJohnson
05-04-2009, 10:11 AM
just like what do i put in the action's "" to make it execute a function?

Fou-Lu
05-04-2009, 01:08 PM
just like what do i put in the action's "" to make it execute a function?

You can use onclick or onsubmit. This isn't a PHP question though, PHP cannot be executed at runtime on the browser. If you want to perform these actions you need to look into using AJAX.

CallumJohnson
05-04-2009, 01:46 PM
I manged to find a workaround:


if($session->isAdmin()){ //Shows link to reset timer if user == admin
echo '<center><form action="" method="post"><input name="reset" '
.'id="reset" type="submit" value="submit" /></form></center>'; }

if ($_POST['reset']){ //Grabs if the submit button has been pressed and executes this code
$username = $session->username;
mysql_query("UPDATE users SET lastcrime='0' WHERE username='$username'");
};



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum