This topic is locked
[SOLVED]

 Function code not returning back to button code

10/6/2012 11:23:18 AM
PHPRunner General questions
W
wildwally author

I have a button in my view page. Within this button I call a function on the server tab using the code shown and it executes as it should with one exception. THe function is not coming back to the button to run the Client After tab code which redirects the user to another page.
Here is the Server tab code calling the function:

transfer_email($params['type'], $params['dept'], $_SESSION['MyUserID'], $_SESSION['MyUserID'], $data['QRID_Num'], $_SESSION['MasterQRID'], $data['RequestedDueDate'], $data['DateCreated']);


Here is the Client after tab code:

window.location.href = "AE_Transfer_Requests_list.php";


And here is the last section of my transfer_email function:



$subject = "Transfer Request for #".$QRID.".";

$ret=runner_mail(array('to' => $to, 'cc' => $cc, 'subject' => $subject, 'body' => $body, 'from'=>$from));

if(!$ret["mailed"])

{

echo $ret["message"];

}

return;

}


As I said the email sends as it should; however the function is not returning back to the Client after to execute the redirect.
Anything I'm doing wrong?

C
cgphp 10/6/2012

Try to remove the return; statement from the last section of your transfer_email function.

W
wildwally author 10/6/2012



Try to remove the return; statement from the last section of your transfer_email function.


Same result as before.

C
cgphp 10/6/2012

Keep firebug opened when you press the button and check the console for errors. Make sure AE_Transfer_Requests_list.php is the real name of the page.

W
wildwally author 10/6/2012



Keep firebug opened when you press the button and check the console for errors. Make sure AE_Transfer_Requests_list.php is the real name of the page.


No console errors to speak of - but js warning and errors out the wazoo (question for another day).
I did narrow thing s down a little more and discovered this.
The code in it's entirety for the server tab is as follows:

global $conn;

$sql = "update AE set JobStatus='9' where AEID=" .$_SESSION['MasterAEID'];

CustomQuery($sql);
//$query = "select * from dbo.AE where AEID = '".$keys['AEID']."'";

//$result = db_query($query,$conn);

//$data = db_fetch_array($result);
transfer_email($params['type'], $params['dept'], $_SESSION['MyUserID'], $_SESSION['MyUserID'], $data['QRID_Num'], $_SESSION['MasterQRID'], $data['RequestedDueDate'], $data['DateCreated']);


By commenting out the second database query the function executes and then redirects the user as intented. However, as you can see here I'm not getting all of my variables I need because the second query is not taking place. Can I not use the typical method for query? Am I causeing the problem by using this method?

C
cgphp 10/7/2012

Remove single quotes from the where clause:

$query = "select * from dbo.AE where AEID = ".$keys['AEID'];

$result = db_query($query,$conn);

$data = db_fetch_array($result);
W
wildwally author 10/7/2012

I wish it was something as simple as you suggest - but it did not work.

C
cgphp 10/7/2012

If you you are selecting only one record on the list page the correct code is:

$query = "select * from dbo.AE where AEID = ".$keys[0]['AEID'];

$result = db_query($query,$conn);

$data = db_fetch_array($result);


If you are selecting more than one record, the correct code is:



$or_clause = '';

foreach($keys as $key => $value)

{

$or_clause .= 'AEID = ' . $value['AEID'] . ' OR ';

}

$or_clause = substr($or_clause,0,-4);

$query = "select * from dbo.AE where " . $or_clause;

$result = db_query($query,$conn);

$data = db_fetch_array($result);
W
wildwally author 10/7/2012



If you you are selecting only one record on the list page the correct code is:

$query = "select * from dbo.AE where AEID = ".$keys[0]['AEID'];

$result = db_query($query,$conn);

$data = db_fetch_array($result);


If you are selecting more than one record, the correct code is:



$or_clause = '';

foreach($keys as $key => $value)

{

$or_clause .= 'AEID = ' . $value['AEID'] . ' OR ';

}

$or_clause = substr($or_clause,0,-4);

$query = "select * from dbo.AE where " . $or_clause;

$result = db_query($query,$conn);

$data = db_fetch_array($result);



I tried your first suggestion as that applies to my situation on the view page, and had no luck. Adding the [0] to the mix doesn't work at all.

C
cgphp 10/8/2012

You are right, $keys[n][field_name] is only valid for list pages. It's hard to say what's happening without seeing your application.

W
wildwally author 10/8/2012

Are you able to recreate the same problem in another instance? Or is this isolated to me?

C
cgphp 10/8/2012

How many records does the following query return ?

$query = "select * from dbo.AE where AEID = ".$keys['AEID'];


Run it directly in SQL server.

W
wildwally author 10/8/2012



How many records does the following query return ?

$query = "select * from dbo.AE where AEID = ".$keys['AEID'];


Run it directly in SQL server.


Returns 1 record - the AEID is the table's index (Primary) field.

C
cgphp 10/8/2012

Post your application on the demo server and send me the demo link. I will try to debug the button request.

W
wildwally author 10/9/2012

Getting errors trying to upload - "Unspecified error Communication Link Failure" and "Unable to create the database script" <BR><BR><BR>Are there other instances of this happening??&nbsp; I found a couple of a similar nature looking through the Forum - but not sure if any resolution was found because the famous "upload to demo account and file support ticket" ended the conversation.<BR><BR><A href="http://www.asprunner.com/forums/topic/19430-customquery-and-button-events/">http://www.asprunner.com/forums/topic/19430-customquery-and-button-events/</A>;

C
cgphp 10/9/2012

You have to ask for custom support. It's hard to say what's happening without seeing your code.

W
wildwally author 10/9/2012



You have to ask for custom support. It's hard to say what's happening without seeing your code.


Tried the demo getting new error
Fatal error: Source: Microsoft OLE DB Provider for SQL Server Description: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. in C:\UserAccounts\www\***_20121009113037\include\dbconnection.mssql.win.php on line 22