RE: [PHP-WIN] simple odbc/insert problem

From: Date: Mon, 20 Aug 2001 15:14:11 +0000
Subject: RE: [PHP-WIN] simple odbc/insert problem
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-8955@lists.php.net to get a copy of this message
> new to php so be nice :) Always! ;) > win2k.... iis5.....ms access.. Check... > // connect to system dsn odbc name login and password or die > $connect = odbc_connect("DB","name","pword") or die (" not > connected"); > > $sql="INSERT INTO basket (Item,Amount,Price) Values > ('$id','$amount','$price')"; > // prepare SQL statement > //$sql_prepare = odbc_prepare($connect,$sql) or die("Couldn't prepare > query."); > // prepare SQL statement > $sql_result = odbc_prepare($connect,$sql) or die("Couldn't > prepare query."); > > // execute SQL statement and get results > odbc_execute($sql_result) or die("Couldn't execute statement1."); > > odbc_free_result($sql_result); > odbc_close($connect); Off the top of my head, you might want to uncomment your sql_prepare statement. As it is: // prepare SQL statement //$sql_prepare = odbc_prepare($connect,$sql) or die("Couldn't prepare query."); // prepare SQL statement $sql_result = odbc_prepare($connect,$sql) or die("Couldn't prepare query."); As it should be: // prepare SQL statement $sql_prepare = odbc_prepare($connect,$sql) or die("Couldn't prepare query."); // prepare SQL statement $sql_result = odbc_prepare($connect,$sql) or die("Couldn't prepare query."); Also, if that's not it...what errors are you getting, if any? Speaking for myself, I end up using odbc_exec() rather than the combination of odbc_prepare()/odbc_execute(). Just a personal preference. You might want to toss in some data validation prior to the $sql definition. It'll help insure you're not trying to insert bad/null values into your database. Hope this helps ya, - Erik

« previous php.windows (#8955) next »