Add Default Value Problem (v2022)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
josejad
User
Posts: 117
Location: Spain

Add Default Value Problem (v2022)

Post by josejad »

Hi all:

I have a table where every user insert its own data, so the id field is hidden and the default value is set to CurrentUserId(). So far so good.

Now, I need another kind of users who can add its own data but other people data too, so this user can see the id field, and it shows a multiple select with other people id's.
In the row_inserting function, I explode the id field, and if it has more than a value, I do a foreach insert in the database.
The problem I've facing is if I just add one record for just one user, different than the one is logged, the id field is set to CurrentUserId(). I realize this so I deleted the default value for the field. But I still get the CurrentUserId() in my db.

Probably the problem is returning TRUE, but the $rsnew['user_id'] should be the form value, but it's CurrentUserId().

    	public function rowInserting($rsold, &$rsnew) {
    		$ArrayIds = explode(',', $rsnew['user_id']); //Comprobamos ahora si se está agregando más de un opoerario por un Jefe de Equipo 	
    		if (count($ArrayIds)>1){ //Inserting more than one user
    			foreach ($ArrayIds as $user){ // Loop through all the records
    				ExecuteStatement("INSERT INTO `mytable`(`user_id`, `date`,) VALUES ('" . $user . "','" . $rsnew['date']");	
    				}				
    				$this->setSuccessMessage($user_id. " added succesfuly");
    			} //foreach
    		} else { //adding just one user (MAYBE DIFFERENT FROM THE USER LOGGED IN)
				
    		}
    		return TRUE;			
    	}

Thanks


arbei
User
Posts: 9384

Post by arbei »

josejad wrote:

ExecuteStatement("INSERT INTO `mytable`(`user_id`, `date`,) VALUES ('" . $user . "','" . $rsnew['date']");

You have syntax error in your SQL.


mobhar
User
Posts: 11726

Post by mobhar »

Did you mean you setup Auto-Update Value to CurrentUserID() from Fields setup?

If so, then it will save the current user id whenever a record is updated.

Or, did you setup the Lookup Table for the user_id field with Multiple option enabled from the Edit Tag pane?


josejad
User
Posts: 117
Location: Spain

Post by josejad »

arbei wrote:

You have syntax error in your SQL.

Just in the post, it's not the real SQL, I've simplified it for posting and it can be wrong


josejad
User
Posts: 117
Location: Spain

Post by josejad »

mobhar wrote:

Did you mean you setup Auto-Update Value to CurrentUserID() from
Fields setup?

If so, then it will save the current user id whenever a record is updated.

It was setup originally, but now it's not set. I thought this was the error and it will be fixed when I delete the Auto-update value.

Or, did you setup the Lookup Table for the user_id field with
Multiple option enabled from the Edit Tag pane?
Yes, now it's set this way, Lookup Table for the user_id with multiple option enabled in the Edit Tag panel


mobhar
User
Posts: 11726

Post by mobhar »

Please post the following information for more discussion:

  1. Table schema (CREATE TABLE ...) including some records example (INSERT INTO ...),
  2. Your Lookup Table setup for the field, including the Link field and Display field setup,
  3. Your latest actual code in Row_Inserting server event.

josejad
User
Posts: 117
Location: Spain

Post by josejad »

Hi friends:

As always, thanks for your help... and... like always too... simplifying my code to post it... the error stops happening, so, it was my fault. Not sure where I set the default value, but now it's solved.

Thanks


Post Reply