What goes wrong?

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
RonP
Veteran Member
Posts: 258
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

What goes wrong?

Post by RonP » 2015-05-30 15:00

Hi,
I have a SQL (PHP?) problem.
in one of the hooks I have added this code: (I have the same code inserted at landen_after_update)

Code: Select all

	function landen_before_update(&$data, $memberInfo, &$args){
//Concatenate with the value given

// RP: 2015-05-19 1 aanpassing
// Samenstellen van url + bestandsnaam (build an url + filname)
// 
	$baseAddressvlaggen = 'http://directory/';
	$update_basevlag	= $data['url'] . $baseAddressvlaggen;
		$sql_string = "UPDATE `landen` set `url` ='" .$baseAddressvlaggen . $data['vlag']."' WHERE landenid = ".$data['selectedID'].";"; 
	$result = sql($sql_string,$o);	
		return TRUE;
	}
On my Local host everything goes well but at my provider I got an SQL-error.
Local Host
PHP Version 5.4.22
MySQL version: 5.5.34

Provider:
PHP Version 5.4.22
MySQL 5.5 (can't find more info)

So what is wrong in the given code?

Thanks in advance
Ron

User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Re: What goes wrong?

Post by shasta59 » 2015-05-31 04:05

Do you have the error code or error log file you can post to give more information?

Thanks

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

User avatar
RonP
Veteran Member
Posts: 258
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: What goes wrong?

Post by RonP » 2015-05-31 10:27

Hi shasta,
Thanks for reacting at my post.

After a hit on the "update" button the next message appears:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When I go back and do a refresh, as suggested, I see that the information ($memberInfo) had been written in the record.

A glance at the "page source" show that the "value" of field "landenid" has no value. Could that be the problem?
<!--
Query:
UPDATE `landen` set `url` ='http://url/256px-Flag_of_Angola.svg.png' WHERE landenid = ;
-->
Ron

User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Re: What goes wrong?

Post by shasta59 » 2015-05-31 13:24

Okay, that does help a bit but as you can see it points to line 1 as the error. It means something in line one is not quite correct. It could be a missing semicolon, a missing or incorrect quote mark etc.

The lack of a value is not relevant as it just means it did not put the value in due to the error. Can you post lines 1 to 10 please to take a look at.

Thanks

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

User avatar
RonP
Veteran Member
Posts: 258
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: What goes wrong?

Post by RonP » 2015-05-31 13:38

Hi shasta59,

I'll put de relevant PHP code in this post.
I think that "linenumbers" starts over again for each function.
I've left the not relevant comment lines, just the ones I juse.

Code: Select all

<?php
	function landen_init(&$options, $memberInfo, &$args){
		return TRUE;
	}
	function landen_header($contentType, $memberInfo, &$args){
		$header='';
		switch($contentType){
			case 'tableview':
				$header='';
				break;
			case 'detailview':
				$header='';
				break;
			case 'tableview+detailview':
				$header='';
				break;
			case 'print-tableview':
				$header='';
				break;
			case 'print-detailview':
				$header='';
				break;
			case 'filters':
	  			$header='';
				break;
		}
		return $header;
	}
	*/
	function landen_footer($contentType, $memberInfo, &$args){
		$footer='';
		switch($contentType){
			case 'tableview':
				$footer='';
				break;
			case 'detailview':
				$footer='';
				break;
			case 'tableview+detailview':
				$footer='';
				break;
			case 'print-tableview':
				$footer='';
				break;
			case 'print-detailview':
				$footer='';
				break;
			case 'filters':
				$footer='';
				break;
		}
		return $footer;
	}

	function landen_before_insert(&$data, $memberInfo, &$args){

		return TRUE;
	}

	/**
	 * Called after executing the insert query (but before executing the ownership insert query).
	 * 
	 * @param $data
	 * An associative array where the keys are field names and the values are the field data values that were inserted into the new record.
	 * For this table, the array items are: 
	 *     $data['land'], $data['vlag'], $data['url'], $data['mutator'], $data['mutatiedatum']
	 * Also includes the item $data['selectedID'] which stores the value of the primary key for the new record.
	 * 
	 * @param $memberInfo
	 * An array containing logged member's info.
	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo
	 * 
	 * @param $args
	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.
	 * 
	 * @return
	 * A boolean TRUE to perform the ownership insert operation or FALSE to cancel it.
	 * Warning: if a FALSE is returned, the new record will have no ownership info.
	*/

	function landen_after_insert($data, $memberInfo, &$args){
//Concatenate with the value given
// RP: 2015-05-19 2 aanpassingen
// 1. ter voorkoming van dubbele bestandstoevoeging als je weer op "wijzigen drukt"
//    [url] wordt overschreven met baseadress van vlaggen 
//    en vervolgens wordt de naam van de vlag er achtergeplakt
//    Bij het aanmaken van een nieuw land wordt automatisch de url + bestandnaam gevuld.
// 2. Nog even de creator invullen, naam van degene die het record heeft ingeoerd.

// 1.	  
	$baseAddressvlaggen = 'http://cloud.kraalmedia.nl/Shipphoto/Ship/vlaggen/';
	$update_basevlag	= $data['url'] . $baseAddressvlaggen;
		$sql_string = "UPDATE `landen` set `url` ='" .$baseAddressvlaggen . $data['vlag']."' WHERE landenid = ".$data['selectedID'].";"; 
	$result = sql($sql_string,$o);	
// 2.
	//sql("update `landen` set `mutator`= '{$memberInfo['username']}' where `landenid` = LAST_INSERT_ID()", $eo);
	// $sql_string = "UPDATE `landen` set `mutator` = " . $new_lidnr . " WHERE id = " . $data['selectedID'] . ";";
			
	// $result = sql($sql_string,$o);
		return TRUE;

	}

	/**
	 * Called before executing the update query.
	 * 
	 * @param $data
	 * An associative array where the keys are field names and the values are the field data values.
	 * Note: if a field is set as read-only or hidden in detail view, it can't be modified through $data. You should use a direct SQL statement instead.
	 * For this table, the array items are: 
	 *     $data['land'], $data['vlag']
	 * Also includes the item $data['selectedID'] which stores the value of the primary key for the record to be updated.
	 * $data array is passed by reference so that modifications to it apply to the update query.
	 * 
	 * @param $memberInfo
	 * An array containing logged member's info.
	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo
	 * 
	 * @param $args
	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.
	 * 
	 * @return
	 * True to perform the update operation or false to cancel it.
	*/

	function landen_before_update(&$data, $memberInfo, &$args){
//Concatenate with the value given

// RP: 2015-05-19 1 aanpassing
// 1. ter voorkoming van dubbele bestandstoevoeging als je weer op "wijzigen drukt"
//    [url] wordt overschreven met baseadress van vlaggen 
//     en vervolgens wordt de naam van de vlag er achtergeplakt
// 1.
	$baseAddressvlaggen = 'http://cloud.kraalmedia.nl/Shipphoto/Ship/vlaggen/';
	$update_basevlag	= $data['url'] . $baseAddressvlaggen;
		$sql_string = "UPDATE `landen` set `url` ='" .$baseAddressvlaggen . $data['vlag']."' WHERE landenid = ".$data['selectedID'].";"; 
	$result = sql($sql_string,$o);	
		return TRUE;
	}

	/**
	 * Called after executing the update query and before executing the ownership update query.
	 * 
	 * @param $data
	 * An associative array where the keys are field names and the values are the field data values.
	 * For this table, the array items are: 
	 *     $data['landenid'], $data['land'], $data['vlag'], $data['url'], $data['mutator'], $data['mutatiedatum']
	 * Also includes the item $data['selectedID'] which stores the value of the primary key for the record.
	 * 
	 * @param $memberInfo
	 * An array containing logged member's info.
	 * @see http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks/memberInfo
	 * 
	 * @param $args
	 * An empty array that is passed by reference. It's currently not used but is reserved for future uses.
	 * 
	 * @return
	 * True to perform the ownership update operation or false to cancel it. 
	*/

	function landen_after_update($data, $memberInfo, &$args){
//Concatenate with the value given

// RP: 2015-05-19 1 aanpasing
// 1. ter voorkoming van dubbele bestandstoevoeging als je weer op "wijzigen drukt"
//    [url] wordt overschreven met baseadress van vlaggen 
//     en vervolgens wordt de naam van de vlag er achtergeplakt
// 2. Nog even de creator invullen, naam van degene die het record heeft ingeoerd.
// 1. 
	$baseAddressvlaggen = 'http://cloud.kraalmedia.nl/Shipphoto/Ship/vlaggen/';
	$update_basevlag	= $data['url'] . $baseAddressvlaggen;
		$sql_string = "UPDATE `landen` set `url` ='" .$baseAddressvlaggen . $data['vlag']."' WHERE landenid = ".$data['selectedID'].";"; 
 	$result = sql($sql_string,$o);	
// 2.
	//sql("update `landen` set `mutator`= '{$memberInfo['username']}' where `landenid` = LAST_INSERT_ID()", $eo);
	//$sql_string = "update `landen` set `mutator`='" .$memberInfo['username']."' where `landenid` = ".$data['selectedID'].";";
	//$result = sql($sql_string,$o);
		return TRUE;
	}


	function landen_before_delete($selectedID, &$skipChecks, $memberInfo, &$args){
		return TRUE;
	}
	function landen_after_delete($selectedID, $memberInfo, &$args){
	}
	function landen_dv($selectedID, $memberInfo, &$html, &$args){
	}
	function landen_csv($query, $memberInfo, &$args){
		return $query;
	}
	function landen_batch_actions(&$args){
		return array();
	}
I hope that this is enough for you to come to a conclusion.

Ron

User avatar
RonP
Veteran Member
Posts: 258
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: What goes wrong?

Post by RonP » 2015-05-31 14:07

Hi shasta59,

HOLD YOUR HORSES!!!

Problem is fixed by me.
What did I do.
I logged on as administrator and went to Utilities --> Rebuild fields.
It appeared to be that I had a mismatch in definition for the
AppGini definition: field mutator VARCHAR(50)
Current definition in the database: Text
After fixing this all went well.
So maybe there should come a "hint" to rebuilding fields whenever an error occurs?

Thanks for your time and support
Ron

User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Re: What goes wrong?

Post by shasta59 » 2015-05-31 14:50

Ron

What I do is a field check after each and every change/update. I used to do it manually until Ahmad added that into the system. Glad you found it. Checking each time is a bit of a chore but only take a minute or so. I also, from time to time change field definitions or size - VARCHAR (40) to maybe 30 or 50 for example based upon inputs etc. So I then also update the listing of fields as found in pageRebuildFields.php in the admin folder.

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

Post Reply