SA-MP Forums Archive
SQL Query Help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SQL Query Help (/showthread.php?tid=284603)



[fixed] SQL Query Help - Memoryz - 19.09.2011

What's wrong with this query?

Код:
INSERT INTO 'acodes' ('thecode') VALUES ('a51G81baJ11a')
Basically all I want to do is insert the "a51G81baJ11a" into "thecode" field, on the acodes database, and I get this error:

Quote:

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 ''acodes' ('thecode') VALUES ('a51G81baJ11a')' at line 1

Can anyone help me out?


---------------------------- PROBLEM WAS FIXED! --------------


Re: SQL Query Help - JaTochNietDan - 19.09.2011

Your syntax is a little strange, you don't need those quotes around the column name and you should use the other quotes around the table name, for example:

pawn Код:
"INSERT INTO `acodes` (thecode) VALUES ('a51G81baJ11a')"



Re: SQL Query Help - Memoryz - 19.09.2011

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Your syntax is a little strange, you don't need those quotes around the column name and you should use the other quotes around the table name, for example:

pawn Код:
"INSERT INTO `acodes` (thecode) VALUES ('a51G81baJ11a')"
Okay that runs perfectly, however when I generate a random string and try to insert it via pawno like this:

pawn Код:
new query[195];
format(query, sizeof(query), "INSERT INTO 'acodes' (thecode) VALUES ('%s')", string);
mysql_query(string);
I get an error:

Quote:

Error (0): Failed to exeute query. 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 '9cSV395Y5AEw' at line 1




Re: SQL Query Help - [Diablo] - 19.09.2011

Quote:
Originally Posted by Memoryz
Посмотреть сообщение
What's wrong with this query?

Код:
INSERT INTO 'acodes' ('thecode') VALUES ('a51G81baJ11a')
Basically all I want to do is insert the "a51G81baJ11a" into "thecode" field, on the acodes database, and I get this error:



Can anyone help me out?
you mean you want to insert into table 'acodes' which contain field 'thecode' and you are inserting value 'a51G81baJ11a' ? database is selected at the beginning..


Re: SQL Query Help - Memoryz - 19.09.2011

Quote:
Originally Posted by [Diablo]
Посмотреть сообщение
you mean you want to insert into table 'acodes' which contain field 'thecode' and you are inserting value 'a51G81baJ11a' ? database is selected at the beginning..
Yea, I am connected to all that, all my other SQL queries run perfectly.


Re: SQL Query Help - DRIFT_HUNTER - 19.09.2011

pawn Код:
new query[195];
format(query, sizeof(query), "INSERT INTO `acodes` (`thecode`) VALUES ('%s')", string);
mysql_query(string);



Re: SQL Query Help - Memoryz - 19.09.2011

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
pawn Код:
new query[195];
format(query, sizeof(query), "INSERT INTO `acodes` (`thecode`) VALUES ('%s')", string);
mysql_query(string);
Quote:

Error (0): Failed to exeute query. 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 '4PYBsw2z0B68' at line 1.

What I am thinking, is that there is a problem with this random string stock?

pawn Код:
stock randomString(strDest[], strLen = 10)
{
    while(strLen--)
        strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
}



Re: SQL Query Help - Jefff - 20.09.2011

Quote:
Originally Posted by Memoryz
Посмотреть сообщение
Okay that runs perfectly, however when I generate a random string and try to insert it via pawno like this:

pawn Код:
new query[195];
format(query, sizeof(query), "INSERT INTO 'acodes' (thecode) VALUES ('%s')", string);
mysql_query(string); // maybe query ? xd
I get an error:
Try :P


Re: SQL Query Help - Memoryz - 20.09.2011

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Try :P
I have tried that already.


Re: SQL Query Help - Jefff - 20.09.2011

Must be
pawn Код:
new query[195];
format(query, sizeof(query), "INSERT INTO `acodes` (`thecode`) VALUES ('%s')", string);
mysql_query(query);
` not ' at acodes and show string