473,513 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Preventing DB crahses with inserts.

Hi,

Is there a function to insert a string safely in the DB?
To ensure that nothing the user can pass will cause an errors or unwanted
behaviour/hacking?

The html function(s) only ensure that there are not special characters.
Would replacing the words WHERE/SELECT/UPDATE/DELETE with some special words
like {W}HERE/{S}ELECT etc be safer?

Many thanks

Sims
Jul 17 '05 #1
10 1572
Sims wrote:
Hi,

Is there a function to insert a string safely in the DB?
To ensure that nothing the user can pass will cause an errors or unwanted
behaviour/hacking?

The html function(s) only ensure that there are not special characters.
Would replacing the words WHERE/SELECT/UPDATE/DELETE with some special words
like {W}HERE/{S}ELECT etc be safer?


mysql_escape_string($rawstring)

Jul 17 '05 #2
> >
The html function(s) only ensure that there are not special characters.
Would replacing the words WHERE/SELECT/UPDATE/DELETE with some special words like {W}HERE/{S}ELECT etc be safer?


mysql_escape_string($rawstring)


But will that guarantee that the query can never be hacked?
Is that the common way of solving the problem?

Sims
Jul 17 '05 #3
"Sims" <si*********@hotmail.com> schrieb:
mysql_escape_string($rawstring)


But will that guarantee that the query can never be hacked?
Is that the common way of solving the problem?


If you use MySQL: Yes.

Regards,
Matthias
Jul 17 '05 #4
Hi !

On Wed, 25 Feb 2004 20:36:40 +0200, "Sims" <si*********@hotmail.com>
wrote:
>
> The html function(s) only ensure that there are not special characters.
> Would replacing the words WHERE/SELECT/UPDATE/DELETE with some specialwords > like {W}HERE/{S}ELECT etc be safer?


mysql_escape_string($rawstring)


But will that guarantee that the query can never be hacked?
Is that the common way of solving the problem?


You have to apply it to each value that you insert. That ensures that
noone can close the single quotes early and run an extra command.

Yes, it is common

Jochen
--
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #5
mysql_escape_string($rawstring)


But will that guarantee that the query can never be hacked?
Is that the common way of solving the problem?


If you use MySQL: Yes.


What do you mean? it is called 'MYSQL_escape_string(...)' so you must be
using MySQL.
Or are you saying that adding an escape string is only safe with MySQL.

Sims
Jul 17 '05 #6
> You have to apply it to each value that you insert. That ensures that
noone can close the single quotes early and run an extra command.
Should i apply the same rule to Numbers? Or should I convert the string to
numbers b4 i add it to the querry?

So if i have a table like

TABLE_TEST
A = TEXT
B = INT(11)

should i do...

UPDATE TABLE_TEST SET A = '".mysql_escape_string($givenA)."',
B='".mysql_escape_string($givenB)."'";

or

UPDATE TABLE_TEST SET A = '".mysql_escape_string($givenA)."',
B='".intval($givenB)."'";

Yes, it is common


Thanks.

Regards,

Sims
Jul 17 '05 #7
"Sims" <si*********@hotmail.com> schrieb:
mysql_escape_string($rawstring)

But will that guarantee that the query can never be hacked?
Is that the common way of solving the problem?
If you use MySQL: Yes.


What do you mean? it is called 'MYSQL_escape_string(...)' so you must be
using MySQL.


Yes.
Or are you saying that adding an escape string is only safe with MySQL.


I think it should be safe with other databases, but I don't know every
existing RDBMS around, so I don't know if this will work everywhere.

Regards,
Matthias
Jul 17 '05 #8
Hi!

On Thu, 26 Feb 2004 10:59:19 +0200, "Sims" <si*********@hotmail.com>
wrote:
You have to apply it to each value that you insert. That ensures that
noone can close the single quotes early and run an extra command.


Should i apply the same rule to Numbers? Or should I convert the string to
numbers b4 i add it to the querry?

So if i have a table like

TABLE_TEST
A = TEXT
B = INT(11)

should i do...

UPDATE TABLE_TEST SET A = '".mysql_escape_string($givenA)."',
B='".mysql_escape_string($givenB)."'";

or

UPDATE TABLE_TEST SET A = '".mysql_escape_string($givenA)."',
B='".intval($givenB)."'";


I prefer latter. Its also closer to the SQL standard I believe.

HTH, Jochen
--
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #9
Hi!

On Thu, 26 Feb 2004 18:07:40 +0100, Matthias Esken
<mu******************@usenetverwaltung.org> wrote:
"Sims" <si*********@hotmail.com> schrieb:
> mysql_escape_string($rawstring)

But will that guarantee that the query can never be hacked?
Is that the common way of solving the problem?

If you use MySQL: Yes.
What do you mean? it is called 'MYSQL_escape_string(...)' so you must be
using MySQL.


Yes.
Or are you saying that adding an escape string is only safe with MySQL.


I think it should be safe with other databases, but I don't know every
existing RDBMS around, so I don't know if this will work everywhere.


Informix and MSSQL uses '' to esacpe a single quote. So it is neither
safe, nor correct there.

HTH, Jochen


Regards,
Matthias


--
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #10
On Thu, 26 Feb 2004 18:07:40 +0100, Matthias Esken
<mu******************@usenetverwaltung.org> wrote:
> mysql_escape_string($rawstring)

But will that guarantee that the query can never be hacked?
Is that the common way of solving the problem?

If you use MySQL: Yes.


What do you mean? it is called 'MYSQL_escape_string(...)' so you must be
using MySQL.


Yes.
Or are you saying that adding an escape string is only safe with MySQL.


I think it should be safe with other databases, but I don't know every
existing RDBMS around, so I don't know if this will work everywhere.


Sensible databases support bind variables/placeholders, separating data from
the SQL, and so avoiding the issue entirely.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1596
by: - | last post by:
how does one prevent someone from directly inserting into a table such that any inserts should be passed to a stored procedure e.g insert_data(....) i have read the manual on revoke, grant but...
18
27683
by: Elroyskimms | last post by:
I have a table using an identity column as its Primary Key and two columns (table reduced for simplicity) EmployeeNumber and ArrivalTime. CREATE TABLE ( IDENTITY (1, 1) NOT NULL , (10)...
7
4502
by: Miktor | last post by:
At the minute I am using the following rather unwieldy function to prevent the console window in Dev C++ from closing before I can see the output from my program: // function to prevent the...
11
14030
by: EoRaptor | last post by:
I`m exporting data from many Lotus Notes databases to a DB2 database using LotusScript. The LotusScript agents commit after EACH update/insert. Nevertheless, I keep getting transaction rollbacks on...
2
1860
by: aboesteanu | last post by:
Data is stored in SQL Server 2000. One table is Person another Item. Each row in the Person table may have associated with it several rows in the Item table. The Item table has a field called...
5
2943
by: Darrel | last post by:
I have a web form that inserts a record into a DB. This function is called from the button_click subroutine. After the record is inserted, I show/hide some different panels and let the page...
1
2184
by: Edwin Grubbs | last post by:
Hello, I have experienced problems with postgres hanging when two inserts reference the same foreign key. It appears that the second insert is waiting for the first insert to release a lock....
0
913
by: Andy G | last post by:
I have a registration site with multiple pages with submit buttons. Everytime the user clicks submit it inserts a record from the information typed on that page into a database and goes to the next...
6
11863
by: Oleg Konovalov | last post by:
Hi, I have a Java/JavaScript GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and...
7
17915
by: chowdary | last post by:
I am developing a PHP-mysql database. It is noted that when the browser window is refreshed the data is inserted again in the database. unfortunately there is no unique keys that I can use to...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5084
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.