odbc INSERT problem


#1

The following line of code:

$sql=“INSERT INTO PublicEvents (Date, Event) VALUES ($date, $event)”;

is giving me the following error:

Parse error: parse error, unexpected T_VARIABLE

I have tried parenthases in different places, brackets, etc and can’t get past this error.

Any ideas???

Don


#2

I assume $date and $event are strings… In which case you need to put them in quotes. And since the SQL statement is a string itself you must escape those quotes so the PHP understands they are characters in the SQL string.

try:
$sql=“INSERT INTO PublicEvents (Date, Event) VALUES (”$date", “$event”)";


#3
:( Tried adding the " and even ' but neither worked. $date and $event are, indeed, string variables.

I am trying to insert a record in an MS Access database on serve with DNS record using odbc commands, if this helps.


#4

can you show a couple of line s above and below the error? Syntax errors usually aren’t on the lines that are given (This is where the error is noticed). You may also wish to echo/print the $sql to varify it is what you are expecting. And just because I am shooting in the dark… are you preparing and then executing or are you using odbc_exec()?

PS - in ODBC you are supposed to use single not double quotes for strings (I didn’t know that) so you shouldn’t have to escape it.

php manual - user comments

rupix at rediffmail dot com 05-Apr-2003 07:05 I tried the following line of code <?php $odbc=odbc_connect("pbk", "root","") or die(odbc_errormsg()); $q="insert into pbk values("$name", "$phone")"; print $q; odbc_exec($odbc, $q) or die("

".odbc_errormsg()); ?>

it does not work. However if I use single quotes instead of " the thing runs smoothly

thus the following would work

<?php $odbc=odbc_connect("pbk", "yourworstnightmare","abracadabra") or die(odbc_errormsg()); $q="insert into pbk values('$name', '$phone')"; print $q; odbc_exec($odbc, $q) or die("

".odbc_errormsg()); ?>

Also having a user dsn is no good on win2k. Always have a System DSN. I don’t know yet what are the implications of the same.


#5

Here is some of the code:

Date/Time:
Event:
<?php #ensure all fields have entries if($date and $event) { #connect to ODBC include 'odbc.php' #create the query $sql="INSERT INTO PublicEvents (Date, Event) VALUES ('$date', '$event')"; #execute the query $rs=odbc_exec($conn, $sql);
The odbc.php works because I am able to pull data out of the table and display.

#6
<?php
#ensure all fields have entries
if(isset($date) && isset($event))  // checks to see if the variable has something.
                                   // your way checks to see if the variable 
                                   // itself is true or false.  You may wish to 
                                   // look at the functions empty() and trim()
{
    #connect to ODBC
    include 'odbc.php';  // <-- was missing a ; at the end of this line.

    #create the query
    // note I removed the  from in front of the '
    $sql="INSERT INTO PublicEvents (Date, Event) VALUES ('$date', '$event')";

    #execute the query
    // technically you are preparing and executing the query... there is a small difference
    $rs=odbc_exec($conn, $sql);