PHP + Access + SQL Help!

From: Date: Sat, 20 Jul 2002 13:08:24 +0000
Subject: PHP + Access + SQL Help!
Groups: php.windows 
Request: Send a blank email to php-windows+get-14860@lists.php.net to get a copy of this message
I am new to PHP but not programming. I have created a simple program to get info from a form and put it into an Access database. Moving to a different database like MySQL is NOT an option! Everything works fine unless the user puts a single quote (') in one of the form text boxes. If they do, an ODBC error is generated and my SQL statement doesn't work. I know this has to do with the way PHP handles quoting, and I have tried addslashes, magic-quotes on/off, and other methods to solve this problem, with no solution. Here are my specs: Windows 2000 Access 2000 PHP 4.2.1 magic-quotes (all) = Off Here is the short version of my code. Please let me know where the problem is and how to solve it. <html> <body> <?php $FName = $_POST['FName']; $LName = $_POST['LName']; $db = odbc_connect("MyData", "", ""); $str_AddRecord = "INSERT INTO Alumni ([FirstName], [LastName]) VALUES ('$FName', '$LName')"; if (!$resp_AddRecord = odbc_exec($db, $str_AddRecord)){ echo "Query error! ODBC error: ", odbc_errormsg(); } else { print("<p class='message'>Record Posted!</p>"); } odbc_close($db); ?> </body> </html> TIA Dewey Williams williams@email.uncc.edu

« previous php.windows (#14860) next »