This topic is locked
[SOLVED]

Insert Button

4/4/2016 2:01:22 PM
PHPRunner General questions
A
Abbas author

Hello,
I try to insert a button and add this code to "Server" tab but it is not working.



//********** Check if specific record exists ************

global $conn;

$strSQLExists = "SELECT * FROM `classes` WHERE `StageID` IS NULL AND `Students` IS NULL AND `SchoolID` = ".$_SESSION["UserID"].";";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do

echo "<script>alert('All Fields must be completed.');</script>";
}

else

{

// if dont exist do

header("Location: schools_edit.php?editid1=" . $_SESSION["UserID"]);

exit();

}


How to execute this code from a button?
Thanks,

Abbas

Sergey Kornilov admin 4/4/2016

Button's code is executed via AJAX. This means you cannot perform a redirect there. If you need to redirect user to another page use ClientAfter event and redirect via Javascript.
See example #4 at https://xlinesoft.com/phprunner/docs/inserting_button.htm