Log in

View Full Version : ODBC SQL Problem


LBK Rules
18-06-2004, 13:07
Well, I started creating a test program that enters data from a HTML table to a database.

I wrote this code, but I keep getting this error:

Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect in c:\ibserver\www\ucs\create_user.php on line 22
Error in SQL

I can't seem to figure out the problem. I know I have everything setup correctly, and I don't understand why it's not working.

<?php

//Include Config Information
require("config.php");

//Connect to Database
$conn=odbc_connect($dbname,$dbuser,$dbpass);

//If Connection Failed, Show Error Message
if (!$conn)
{
exit("Connection Failed: " . $conn);
}

//Insert Data into Database
$sql="INSERT INTO Sellers (Username, Password, LastName, FirstName, Address, City, State, ZIP, Phone, EMail) VALUES ($UserName_TextBox, $Password_TextBox, $LastName_TextBox, $FirstName_TextBox, $Address_TextBox, $City_TextBox, $State_TextBox, $ZIP_TextBox, $Phone_TextBox, $EMail_TextBox)";

$rs=odbc_exec($conn,$sql);
if (!$rs)
{
exit("Error in SQL");
}

odbc_close($conn);

echo "Sucessful!";

?>


Note: I am using ODBC instead of MySQL since I am developing this for a server without MySQL.

LBK Rules
18-06-2004, 23:29
Ok, I have figured it out, with the help of my dad.

I didn't include single-quotes ( this ' ) around the varibles that might have spaces in it.

Example:

$sql="INSERT INTO Sellers (Username, Password, LastName, FirstName, Address, City, State, ZIP, Phone, EMail) VALUES ('" .
$UserName_TextBox . "', '" . $Password_TextBox . "', '" . $LastName_TextBox . "', '" . $FirstName_TextBox . "', '" .
$Address_TextBox . "', '" . $City_TextBox . "', '" . $State_TextBox . "', '" . $ZIP_TextBox . "', '" . $Phone_TextBox .
"', '" . $EMail_TextBox . "')";

$Address_TextBox
would not work, but
$rest_of_sql1 . ", '" . $Address_TextBox . "', " . $rest_of_sql2
would.

I hope this helps somebody.