Pass to php file

Hi Ben, very nice of you to help me. Since it's passing through the data to a .php file, I thought this was separate from databases. What should I do exactly ?

If you can point me to a video that explains this that is great too.


Normally, when I start a new CMS type project, I go through the following steps.

  1. create a database with the necessary tables
  2. create Server Actions
  3. bind the data to the user sections.

You already have an existing database with tables, you will have to familiarise yourself of the structure of the database.

To give you an idea of what I am talking about, please have a look at this series

Although the series show how to create an image gallery, the basics are the same for your project. All database actions are based on

  • Creating a new item
  • Reading or viewing the items
  • Updating items
  • Deleting items

The first letters of each line spells CRUD.

The case that you have shown is the Update, where a record is updated. The update is shown in part #6 and part#15 of the tutorial.

Once you are aquainted with Wappler, please come back here with particulars of your database. We will then take it from there.

Good luck.

Hi Ben,

Thank you for your help. I literally want it to be as follows:

  1. User presses a button in the table:

  1. Then this command runs:

exec ('cd /home/apis/mrpEasy/ && php ./SqltoWOPO.php '.$sku. ' '.$quantity." ".'1>web.log 2>&1');

Where “SKU” and “quantity” are values from the table.

I don’t want to rebuild this PHP exec thing using wappler, I just simply want this PHP code to be executed. Is that technically possible? To execute this PHP code when I press the “bestel” button?

Maybe a different way of asking is, can I execute “custom” PHP in Wappler? And if so, how?

You could see Wappler as being a visual code editor. Its best features are demonstrated when full use is made of Server Connect and App Connect, the former is for server side activities, while the other looks after the client side of things.

If you do not intend to use these features, then Wappler has no advantage above other code editors.

If, as you say, you do not want to rebuild the PHP, that is OK, Wappler will handle the coding side of things. The execution of the PHP code is done by the server. In other words, the page, as you have it now, will work, regardless of which IDE (integrated development environment) you want to use.

Having said that, my advice is to start using Wappler with all of its tools. I would create a Server Connect action to gather the information from the database and use that information to populate the table. Then I would create a second Server Connect action that updates the table when the Bestel button has been pressed. Both of these actions are very straight forward and should take no more than 10 minutes each to accomplish.

If you agree with the proposal, please do an export of the database and post the SQL in a zip format for me to replicate in my own system. Also post a zip file of the PHP file that runs the command so that I can see which actions take place. From there I will show you how easy it is to Wapplerize things.

Hi Ben,

It’s not really that easy, there have been built a lot of different tables/databases and API calls already. It’s not just a simple SQL export where you can work with.

I have been trying to rebuild it, and have been getting quite far but still need some help. Is there any chance I could go on a skype call with you or someone else who can help me with this?

I am also not able to upload any php files here in this forum, it’s forbidden apparently. So I will copy the code below


ini_set('display_errors', 'On');
ini_set('memory_limit', '-1');
if ($argc == 3) {
  $thisrec = 'select * FROM nh_ProdOrderWrap where status=\'voorstel\' and sku=\''.$argv[1].'\' limit 1;';
  $thisamount = $argv[2];
  } else {
  $thisrec = 'select * FROM nh_ProdOrderWrap where status=\'in_bestelling\' order by status,leverancier desc;';
  $thisamount = 0;
print ("***");
require_once ( '../NatHeroes/initsql.php' );
require_once  "MRPEasyRestClient.php";
require_once  "../InventoryPlanner/InventoryPlannerClient.php";

$url = '';
$rest = new MRPEasyRestClient();
$rest->setAccessKey(')s e c r e t;

// setup SQL transaction
$txt = 'USE NatHeroes;';
$stmt = $dbh->prepare($txt);
$ret = $stmt->execute();
//$txt = 'select * FROM nh_ProdOrderWrap where status=\'in_bestelling\' order by status,leverancier desc;';
$stmt = $dbh->prepare($thisrec);

foreach ($dbh->query($thisrec) as $SQLrow) {
	if ($thisamount<>0){ //use value from commandline
          $SQLrow['Aanvullen'] = $thisamount;
	$thisBooking = $SQLrow['id'];
		$data = array(
    		'sku' => $SQLrow['sku'],
    		'article_id' => $SQLrow['mrp_artikelID'],
    		'quantity' => $SQLrow['Aanvullen'],
    		'assigned_id' => '1',
    		'site_id' => '1');
		print ('CreateManOrder:'.$data['sku'].':' .$data['article_id'].':' .$data['quantity'].':'
		.$data['assigned_id'].':' .$data['site_id']."\n");
	$leverancier = $SQLrow['Leverancier'];
	if (strtoupper($leverancier) == 'NATURAL HEROES')	{
		print("Insert into mrp:\n");
		$error_insertingInMrp = '';
		$man_ord_id = MRPcreateManOrder($rest, $url, $data);
	 	if (!empty($man_ord_id->errors)){
			$error_insertingInMrp = "Error: MRP: ".$error ;
		$tabledata = ReadMrpTable($rest,$url,'manufacturing-orders?man_ord_id='.$man_ord_id);
		$invPlanPO = $NewMO;}
	else {
	// bepaal PO omdat er geen MO is
		$txt = 'select `NatHeroes`.`fnGetLasPurchOrdnr` ();';	
		$stmt = $dbh->prepare($txt);
   		$ret = $dbh->query($txt);
		foreach ($dbh->query($txt) as $SQLret) { $invPlanPO = $SQLret[0]; }
		$temp = ++$invPlanPO; $invPlanPO = $temp;
	$data = array(
			'addMySKUs'=> true,
			'addBarcodes'=> true, 
			'status'=> 'open',
    			'warehouse' => 'c955_330498075',
    			'reference' => $invPlanPO,
    			'expected_date' => $SQLrow['Verwachte Lever Datum'],
    			'vendor' => $SQLrow['Leverancier'],
			'items' => array(
				'0' => array(
    					'id' => $SQLrow['id'],
    					'sku' => $SQLrow['sku'],
    					'title' => $SQLrow['Omschrijving'],
    					'replenishment' => $SQLrow['Aanvullen'],
    					'barcode' => $SQLrow['barcode'],
    					'cost_price' => $SQLrow['cost_price']
	print("Insert into InvPlan:\n");
	$result=InvPlanPostPO($restI, $urlI, $data);
	$tableitem = new stdClass();
		$tableitem->id = $SQLrow['id'],
		$tableitem->sku =  $SQLrow['sku'],
		$tableitem->title = $SQLrow['Omschrijving'],
		$tableitem->replenishment =  $SQLrow['Aanvullen'],
		$tableitem->werkopdrachtnr = $NewMO,
		$tableitem->inkoopopdrachtnr = $invPlanPO,
		$tableitem->status = ($error_insertingInMrp != '' ? $error_insertingInMrp : 'aangemaakt'),
		$tableitem->opdrachtdatum = date('Y-m-d H:i:s'),
		$tableitem->opdracht_door = 'webtool',
		$tableitem->verw_levdatum = date('Y-m-d H:i:s',$SQLrow['Verwachte Lever Datum']),
		$tableitem->datum_opgeleverd = NULL,
		$tableitem->afgehandel_door = NULL,
		$tableitem->aantal_geproduceerd = NULL,
		$tableitem->vendor_levering = 
		$tableitem->warehouse = $SQLrow['warehouse'],	
		$tableitem->lead_time =  $SQLrow['lead_time'],	
		$tableitem->review_period =  $SQLrow['review_period'],	
		$tableitem->under_value =  $SQLrow['under_value'],	
		$tableitem->oos =  $SQLrow['Uitverkocht'],	
		$tableitem->vendor_conn =  $SQLrow['vendor_conn'],	
		$tableitem->vendor_rule =  $SQLrow['vendor_rule'],	
		$tableitem->mrp_artikelID =  $SQLrow['mrp_artikelID'],	
		$tableitem->cost_price =  $SQLrow['cost_price'],	
		$tableitem->barcode =  $SQLrow['barcode']
	$SQLinsert = db_build_insert('nh_productieOrders',$tableitem);
	$stmt = $dbh->prepare($SQLinsert);
	$ret = $stmt->execute();

//get MO-text
//$a = ReadMrpMan_ordersIntoDB($rest,$url,'manufacturing-orders',$dbh,'NatHeroes','MRPmanufacturing_orders')