This topic is locked
[SOLVED]

Custom Button Server Event SQL Update where id='$id'

10/29/2022 4:36:50 AM
PHPRunner General questions
1NET author

I have made a custom button on a list page for each record that says "Assign Now"

When the button is pressed I want it to update a MySQL DB Table row with a "1" in the Assigned field

| order_id | Assigned |

| 1 | NULL |
| 2 | 0 |
| 15 | NULL |

I am using this in the server Event as per The Additional Troubleshooting Tips at https://xlinesoft.com/phprunner/docs/troubleshooting_custom_buttons.htm

$result["txt"]="";
foreach($keys as $idx=>$val)
{
$sql = "update orders set Assigned='1' where order_id=".$val["order_id"];
$result["txt"].=$sql."
";
//CustomQuery($sql);
}

The issue is that every button on a row that has a order_id less than 2 charactors (ie. 1 or 2 or 5 or 8) works perfectly well
The rows with an order_id that have 2 or more characters (ie. 15 or 16 or 22 or 3325) do nothing
the script returns this

update orders set Assigned='1' where order_id=1

  • COMPLETE!

It should say...

update orders set Assigned='1' where order_id=15

  • COMPLETE!

Can anyone see an error in the Events->Server script from the Troubleshooting Tips page?

admin 10/29/2022

I'm not sure I understand your question.

Are you asking if someone sees an error in your code or you asking for more troubleshooting tips?

1NET author 10/30/2022

The Code listed as a solution @ https://xlinesoft.com/phprunner/docs/troubleshooting_custom_buttons.htm
Does not work

The issue is
if the ID of the record in the MySQL database has 2 digits (ie. 10 )
the script returns this
update orders set Assigned='1' where order_id=1
order_id should be 10 not 1

Other record in the database with an ID that is 1 digit long works perfectly well with this script

is there an issue with your code from the above listed forum page?
foreach($keys as $idx=>$val)
is this scriot limiting the result to single digits only?

admin 10/30/2022

https://xlinesoft.com/phprunner/docs/troubleshooting_custom_buttons.htm is an article that provides troubleshooting tips.

If you are looking for code examples check this article:
https://xlinesoft.com/phprunner/docs/inserting_button.htm#examples

Check examples #1 or #2 there.

1NET author 10/30/2022

Thanks for your suggestion

I've modofoed the code to produce the correct result
It now works

The Fix

Client Before

params["txt"] = "";
ajax.setMessage("Assigning Order Now");

Server

global $dal;
$record = $button->getCurrentRecord();
if ($record["order_id"])
{
$sql = "update orders set Assigned='1' where order_id=".$record["order_id"];
$result["txt"].=$sql."
";
CustomQuery($sql);
}

Client After

var message = result["txt"] + " - COMPLETE!";
ajax.setMessage(message);
location.reload();

Again thanks for your assistance