Re: Anyone on? INSERT INTO with MS Access problem

From: Date: Sun, 01 Oct 2000 23:13:48 +0000
Subject: Re: Anyone on? INSERT INTO with MS Access problem
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-2870@lists.php.net to get a copy of this message
I don't think the problem is the format. In MS Access, when you insert a date, you have to enclose it in "#", like this: #07/11/1982#. Sometimes it's useful the function datevalue(date), which you can use even in a SQL statement. Finally, dates in SQL statement have to follow the american syntax, that is mm/dd/yy. "Asendorf, John" wrote: > > Gonzalo, > > Could I ask you to see what you have your Fecha field properties set to in > Access? Particularly the "Format:" field > > --------------------- > John Asendorf - jasendorf@lcounty.com > Web Applications Developer > http://www.lcounty.com - NEW FEATURES ADDED DAILY! > Licking County, Ohio, USA > 740-349-3631 > > > -----Original Message----- > > From: Gonzalo Vera [mailto:gvz@eucalipto.net] > > Sent: Sunday, October 01, 2000 6:23 PM > > To: Asendorf, John > > Subject: Re[2]: [PHP-WIN] Anyone on? INSERT INTO with MS > > Access problem > > > > > > Here's an actual example of what was sent (and actually taken) by > > Access. > > > > insert into [préstamos] (LClave, LCopia, Centro, Contacto, Fecha) > > values > > ('G-2/78','11','AM','Myself','1-Oct-00'); > > > > As you can see my date format is wildly off standard, but I just > > noticed that the Access manual says that when using SQL statements > > you should use US format (strange, as my non-US format is working), > > soooo... at least the manual is one place not to look for help in this > > case :-/ > > > > Why not try YYYY-MM-DD format, Unix style? I've sucesfully used it > > also, both insert and update. Frankly, I don't think format is the > > problem, but, nothing to lose. > > > > Gonzalo. > > > > > I'm afraid that that didn't do the trick... > > > > > could it be my date format: 07-19-1971 for instance? > > > > > --------------------- > > > John Asendorf - jasendorf@lcounty.com > > > Web Applications Developer > > > http://www.lcounty.com - NEW FEATURES ADDED DAILY! > > > Licking County, Ohio, USA > > > 740-349-3631 > > > > > > >> -----Original Message----- > > >> From: Gonzalo Vera [mailto:gvz@eucalipto.net] > > >> Sent: Sunday, October 01, 2000 5:37 PM > > >> To: Asendorf, John > > >> Cc: PHP Windows > > >> Subject: Re: [PHP-WIN] Anyone on? INSERT INTO with MS > > Access problem > > >> > > >> > > >> I usually enclose date data in #, like: > > >> > > >> > $sql = "INSERT INTO FrontpageNews (headline,place,author,story, > > >> > date) VALUES > > >> > ('$headline','$place','$author','$story', > > #$date#);"; > > >> > > >> That's the way Access likes to recognize dates. > > >> > > >> Gonzalo. > > >> > > >> > Hi everyone: > > >> > > >> > I'm having some problems and I'm out of guesses... I'm > > >> attempting my first > > >> > INSERT INTO with MS Access. I've had wonderful successes > > >> with SELECT and > > >> > then using that info. But I'm really quite stuck here. > > >> > > >> > My first problem is getting the date to not break the > > >> INSERT INTO sql. > > >> > > >> > When I have date and '$date' in the INSERT INTO sql, I get > > >> this error: > > >> > Warning: SQL error: [Microsoft][ODBC Microsoft Access > > >> Driver] Syntax error > > >> > in INSERT INTO statement., SQL state 37000 in SQLPrepare in > > >> > D:\InetPub\wwwroot\is\website\test_center\newsinputter.php > > >> on line 85 > > >> > > >> > otherwise it doesn't error out BUT > > >> > > >> > BUT BUT BUT > > >> > > >> > It doesn't put the data into the table either!!!! no > > >> error, but no data > > >> > either! Arrrgh! > > >> > > >> > Any Suggestions? Thanks in advance, > > >> > > >> > John > > >> > > >> > Code Below > > >> > ------------- > > >> > > >> > <?php > > >> > //check date > > >> > //yes, Friedl's book will teach you how to make regexes > > >> like this too! > > >> > if ( !ereg > > >> ("(0?[0-9]|1[0-2])[-/]([0-2]?[0-9]|3[01])[-/]([0-9]{4})", $date ) > > >> > ) { > > >> > //date is invalid > > >> > die ("Please press your browser's back button and enter > > >> a date in the > > >> > format MM-DD-YYYY"); > > >> > } > > >> > > >> > // create connections > > >> > $connection = odbc_connect("web.mdb","",""); > > >> > > >> > // test connection > > >> > if (!$connection) { > > >> > echo "Couldn't make a connection!"; > > >> > exit; > > >> > } > > >> > > >> > echo "TESTING: $date <br> $headline <br> $place <br> > > >> $author <br> $story > > >> > <br><br><br>"; > > >> > > >> > /* I'll look into these functions a little deeper later > > >> > function AccessAddSlashes($S) > > >> > { > > >> > > >> > $S=str_replace("\\'","''",$S); > > >> > $S=str_replace("\\\"","\"\"",$S);( > > >> > return $S; > > >> > } > > >> > > >> > function AccessStripSlashes($S) > > >> > { > > >> > $S=str_replace("\"\"","\\\"",$S);5 > > >> > $S=stripslashes($S);" > > >> > return $S; > > >> > } > > >> > */ > > >> > > >> > $headline = stripslashes ($headline); > > >> > $place = stripslashes ($place); > > >> > $author = stripslashes ($author); > > >> > $story = stripslashes ($story); > > >> > > >> > echo "TESTING AFTER SLASH STRIP: $date <br> $headline <br> > > >> $place <br> > > >> > $author <br> $story <br>"; > > >> > > >> > > >> > // create SQL statement ******(this errors out if I put > > >> date and '$date' > > >> > into the fields and values)***** > > >> > $sql = "INSERT INTO FrontpageNews8 > > >> (headline,place,author,story) VALUES > > >> > > > >> > ('$headline','$place','$author','$story');"; > > >> > > >> > // prepare SQL statement > > >> > $sql_insert = odbc_prepare($connection,$sql); > > >> > > >> > /* execute SQL statement and get results > > >> > odbc_execute($sql_insert); */ > > >> > > >> > > >> > /* check for errors */ > > >> > if (!odbc_execute($sql_insert)) { > > >> > /* error */ > > >> > echo "Whoops"; > > >> > } else { > > >> > echo "You did it!"; > > >> > } > > >> > > >> > odbc_close($connection); > > >> > > >> ?>> > > >> > > >> > --------------------- > > >> > Founder and Only Member of > > >> > The 'What Kind of Idiot Uses PHP with IIS with Oracle on > > >> NT?' Consortium > > >> > > >> > John Asendorf - jasendorf@lcounty.com > > >> > Web Applications Developer > > >> > http://www.lcounty.com - NEW FEATURES ADDED > > >> > DAILY! > > >> > Licking County, Ohio, USA > > >> > 740-349-3631 > > >> > > >> > > >> > > >> -- > > >> PHP Windows Mailing List (http://www.php.net/) > > >> To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > > >> For additional commands, e-mail: php-windows-help@lists.php.net > > >> To contact the list administrators, e-mail: > > >> php-list-admin@lists.php.net > > >> > > > > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > For additional commands, e-mail: php-windows-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.windows (#2870) next »