Can't get LAST_INSERT_ID() to work from ASP classic - mysql

This question is driving me crazy and I hope you can help. I want to use the following sql for a MySQL-database:
INSERT INTO Prenumeranter (Pren_Namn,Pren_Email) values ('Testing','test#test.com');
UPDATE Prenumeranter SET Pren_kod = encrypt(LAST_INSERT_ID()) WHERE Pren_id = LAST_INSERT_ID();
This code works perfect if I run it in PhpMyAdmin but if I run it on my asp classic page it only gives errors for the LAST_INSERT_ID(). I have tried to rewrite it in different ways, but they all work in PhpMyAdmin but not from the asp page. The error message is:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[MySQL][ODBC 5.1 Driver][mysqld-5.5.30-cll-lve]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 'UPDATE Prenumeranter
SET Pren_kod = encrypt(LAST_INSERT_ID()) WHERE Pren_id = LA' at line 1
/sida.asp, line 122
If I replace the LAST_INSERT_ID with an int value ('85' or something) everything works fine from asp page too so it must be a problem with the LAST_INSERT_ID().
I appreciate all help that can get me back on track...

Related

'Cant get attributes from Select' while setting up Query for export data task in DBeaver

Hey so I'm trying to set up an export data task in DBeaver, because I want to export some data to another database and I want to query the date in beforehand. So I'm trying to use this SELECT statement
SELECT *
FROM resource
WHERE assignedteamid = 2 AND active;
which works fine on its own but when I'm trying to add this query in the Task setup screen and click on continue I get this Error
Can't get attributes from `SELECT * FROM resource WHERE assignedteamid = 2 AND active;`
Reason: SQL Error [1064] [42000]: 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 'LIMIT 0, 1' at line 4
I already tried to change up the query but I have no clue what I need to do to fix this problem. I appreciate any help.
Thank you!

MySQL syntax error(the query works perfectly fine in mysql but somehow ends up giving error in jsp)

I am trying to update database in mysql but when i use the query in mysql it works perfectly fine......but when i update it through jsp it gives me an error as
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
this is query of JSP: (in content i do not add any closing brackets like ')')
insert into location_"+username+"
values('"+coordinates+"','"+content+"',"+latitude+","+longitude+");
i use stmt.executeUpdate(q1);
the above query is stored in q1..
this is query in mysql:(this works absolutely fine)
insert into location_user1 values('{lat: 19.2222, lng: 73.9781}','random coordinate from database', 19.2222, 73.9781);
i have found out that this error is somewhat common..yet i could not find out any solution...PLease Help!! Thank You!! This error is so frustrating..
Try printing q1 and execute the printed output in MySQL.
At jsp end, the query is not getting properly built and this only is leading to the issue.

is there a Syntax like MSSQL's "INSERT INTO table (fieldlist) OUTPUT INSERTED.id VALUES" in MySQL?

I like to get the id of the record that's been inserted by a statement as a result of that statement. I know about SELECT LAST_INSERT_ID(); but can not use it in my scenario because LAST_INSERT_ID() works on a per-connection-basis and I am currently using a convenient function in my framework to access the db - but that convenience implies that the connection only exists during execution of that statement - so I'm wondering if there is a syntax as in Microsoft SQL Server as shown in the title?
In my environment, I am building the command looks like this:
INSERT INTO Bookings (Status,YEarlyBird,YDays,YHotel,YBanquet,Name,Company,Address,Town,Region,Postcode,CountryCode,Second
Name,SecondEmail,RoomType,SpouseMealPlan,Notes,Conference_VAT,Accommodation_VAT,Conference_id,InvoiceAmount,Conferen
ceGross,Accomodation,SpouseGross,SpouseNet,TotalGross,TotalNet,ConferenceNet,Courses) VALUES (:<C1:,:<C1:,:<C6:,:<C
6:,:<C1:,:<C12:,:<C28:,:<C15:,:<C7:,:<C5:,:<C5:,:<C2:,:<C1:,:<C1:,:<C15:,:<C3:,:<C1:,:<F:,:<F:,:<I:,:<F:,:<F:,:<F:,:
<F:,:<F:,:<F:,:<F:,:<F:,:<C1:);SELECT LAST_INSERT_ID();
(the :<:-stuff are placeholders for Bind-variables)
If a ran the INSERT on its own, it works. If I append the SELECT LAST_INSERT_ID() as shown, I get:
[MySQL][ODBC 5.3(w) Driver][mysqld-5.7.18-log]You have an error in your SQL syntax; check the manual that corresponds to y
our MySQL server version for the right syntax to use near 'SELECT LAST_INSERT_ID()' at line 1
P.S: using that convient way to access the DB is perfectly ok in my use-case because the DB is written once only - exactly with the statement i am working on.

(ASP) MS Access -> MySQL: Error in Select, where [..] strings

I am using a portal system on my website and modified the ASP code heavily.
Since the website is growing, I want to migrate from MS Acces to MySQL.
Now, I think the portal I'm using (and some code I inputted) aren't MySQL compatable, because when I switch to the MySQL database, I get the following error.
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[MySQL][ODBC 5.1 Driver][mysqld-5.1.55-community]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 '[EzModuleID],
[ModName] From EzCore_Plugin Where IsModActive='1'' at line 1
[website]\WWWROOT\BOXX\INCLUDES../../includes/include.asp, line 3736
The SQL string regarding this line is the following:
Select [EzModuleID], [ModName] From EzCore_Plugin Where [IsModActive] = 1;
Im new to MySQL and I can't find why this is giving an error.
I've tried the quote's around 1, removing [], removing the space..
I think that when I figure out why this is causing an error, I can continue modifying the rest to make the website work on mysql.
Lose the square brackets
(I might as well post this as the answer rather than a comment)
In MySQL column and table names can be escaped with the backtick character ` or if the ANSI SQL mode is enabled with double quotes ".
Your WHERE clause (according to the error message) is Where IsModActive='1'. This works if IsModActive is a text column. If it is numeric, drop the single quotes. If IsModActive is a Boolean, change the clause to Where IsModActive IS true.
See: is operator

Basic MySQL Error using UPDATE query

I have no idea what I've done wrong, I've tried a lot of different things so far, reworking the statement, etc, but nothing seems to work.
I'm getting this error:
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 'SET content='this is content', active='1' WHERE id='1'' at line 1
And this is the query I'm using:
UPDATE Pages SET title='$title', SET content='$content', active='$active'
WHERE id='$id'
I've checked to make sure that it's not what's being inserted that is the problem.
Delete the second SET into your query.
You have:
SET title='$title', SET content='$content'