[SOLVED] DELETE FROM gives error in Events.

Very strange bug I think.

Here is the working code from project. Import into new install of SC8 on hosted environment.

/**
 * Delete a record on another table
 */

// SQL statement parameters
$delete_table  = 'mylocks';      // Table name
$delete_where  = "RecordLocked = '{RecNbr}'"; // Where clause

// Delete record
$delete_sql = 'DELETE FROM ' . $delete_table
    . ' WHERE '      . $delete_where;
sc_exec_sql($delete_sql);

When trying to edit this code at all… will not save… I get this error from the server: [HR][/HR] Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster@MYDOMAIN to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request. [HR][/HR] Apache/2.4.16 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4 Server at MYDOMAIN Port 80 [HR][/HR]

[SIZE=14px]The problem seems to be the words DELETE FROM… because if I change the line to:[/SIZE]

$delete_sql = 'DELETE'.' FROM ' . $delete_table

[SIZE=14px]Then it saves and works ok.[/SIZE]

That makes sense…
Your first $delete_sql becomes when evaluated something like: DELETE FROM mylocks WHERE RecordLocked =‘this->RecNbr’
This is because {RecNBr} is actually surrounded by curly braces which means for scriptcase to put make this into php code.
Just check your generated *_apl.php code for RecNbr, you should be able to find it quickly.
If you would have used:
$deletewhere = [SIZE=12px]"RecordLocked = ".{RecNbr}[/SIZE]
then it would have assigned the value “RecordLocked” . ($this->RecNbr) to $deletewhere (the thing ($this->RecNbr value thus)).
Experiment and you’ll see what I mean.

Thank you for your direction.

Now I am very confused though because I cannot put this in my events either:

if (1=1){
// Do nothing
}

I get the same error and it won’t save the event.

This is wrong… Because you obviously meant: if (1==1) …
and not 1=1 since that is an assignment which cant be done. == is a comparions.
See w3schools: http://www.w3schools.com/php/php_operators.asp

Not sure what happened there since I Put

if (1==1){
// Do nothing
} 

Which gives me the server error.
I have never seen anything like this before.

You are right… I actually did have 1==1 and get the error.
This is very strange indeed… as if I put the above code in the event empty, then it works… but if I put it at the end of my code already in the event then I get the Server error.
I am going to try to get the server to send the errors to the screen… maybe that will shed some light on whats happening.
Scriptcase Support seemed to think this was an issue with my web browser… but I am getting this in all my browsers so I think its perhaps something on my server end.
This is the first time I have run a hosted scriptcase development environment, and it took some work to get it working… Perhaps its still missing something?

Thanks for your help so far!

Got it!

The problem was on my hosted server. Scriptcase was causing a security measure to be flagged on the DB… the events.php file (Part of Scriptcase that writes out events I assume) was being blocked by my host.

They allowed that trigger to work and now its working great!

I think it had something to do with how long the event code was that I was working on. Thats why it would only happen when the check was near the bottom of my event (Or seemed that way) because when I would save it… I would get the error.

I hope this helps someone else one day.

1 Like