473,320 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

INSERT INTO sporadically fails - suggestions for possible reasons?

I have a website that inserts data into a database, using the code
below. Basically, I've got one INSERT INTO statement that inserts one
line of data into one database, and and then a php for loop that
inserts multiple lines into a database with successive INSERT INTO
statements. The for loop seems to work fine, but $statement1
sporadically fails to insert data properly into the database-- eg, for
one of the values, it'll spontaneously not insert all characters. At
times, the $statement1 fails to insert into the database completely. There is little chance that accidental characters are being entered (such as apostrophes), just because of the kind of data.


Any suggestion? Again, I'm not a programmer and particularly not used
to SQL, so if anyone responds, please keep it simple! Thanks!

L


<?


$odbc = ODBC_CONNECT('user','root','password') or die
(odbc_errormsg('Could not connect to requested data source'));


$statement1 = odbc_exec($odbc,"INSERT INTO
database1(user,sessiondate,test,score1,score2,scor e3,score4,score5)
VALUES
('$username','$date','$expName','$score1','$score2 ','$score3','$score4','$s*core5')");


for ($i=0;$i<sizeof($lbl);$i++) {
$foo = explode(" ",$lbl[$i]);
$statement2 = odbc_exec($odbc,"INSERT INTO
database2(i,user,sessiondate,stimdone,response,tri aldur,acc,status)
VALUES
('$foo[0]','$username','$date','$foo[1]','$foo[2]','$foo[3]','$foo[4]','$fo*o[5]')");



}


odbc_close($odbc);

?>
May 16 '07 #1
1 1883
Motoma
3,237 Expert 2GB
If you believe that apostrophes are being put into the insert statements, use the addslashes() function to appropriately handle them.

This goes to show you that you should ALWAYS validate your data. Always.
'Nuff said.
May 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joe | last post by:
Hey, I'm going to give some background on my situation in case anyone can point out a way around my problem altogether... for the problem itself, please skip to the bottom of the post. thanks....
2
by: Trent | last post by:
Hey All, I am new to javascript and currently coding a site with scripts that are beyond my level of understanding. The problematic page has thumbnail images that can be clicked on to zoom in....
12
by: Martin_Hurst | last post by:
Has some one come up with a similar type script that could be used in a Postgresql database? The script below was created for a SQLServer database. Thx, -Martin ...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
3
by: Bon | last post by:
Dear all How can I convert a datetime in Short Date format to General Date format and then insert into SQL database? I get a date from a field using Request("in_date"), which is in Short...
0
by: radiodes | last post by:
I am very new to SQL/Access, and only use it very limitedly, so apologies ahead of time. I have a website that inserts data into an access database, using the code below. Basically, I've got...
2
by: =?Utf-8?B?Y2F0?= | last post by:
We recently moved an older ASP.NET 1.1 code base on to ASP.NET 2.0, .NET 3.0 and Windows 2003 Server SP2. We started experiencing the following issue with the web cache (the code is straightforward...
8
by: jonmundsack | last post by:
I have an intranet site on my LAN which has "anonymous access" turned OFF, and "integrated Windows authentication" turned on. This allows me to access the "AUTH_USER" server variable, which I use...
0
by: kj | last post by:
I have a script that calls the function write_tmpfile, which looks something like this: def write_tmpfile(f, tmpfile): # set-up code omitted in_f = popen("""grep -v '^\\$' %s |\ grep ']' |\...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.