Link to home
Start Free TrialLog in
Avatar of lilyyan
lilyyan

asked on

is there a syntax error in my php sql statement

hello:

i'm using the follwoing code insert data to a table. i'm using odbc connection in ms sql 2005

but the insert statement is failed to exected.

the error is : SQL state 00000 in SQLExecDirect  in line : odbc_exec($dbconnect, $SQL);

i tried both
 odbc_execute ($query, $parameters);
odbc_exec($dbconnect, $SQL);

it's just not working...

could some expert here help me? thank you so much !

$SQL = "INSERT INTO myProject (Project_Title, Time_Location_Group, Subject_Area, Professor_Name,
Professor_Email,Project_Description, Student_Qualifications, Hours, Credits,
Credit_Hours, Status, Affiliation_Centers, Project_Links, Entry_Date) VALUES 
		('{$projtitle}','{$projlocation}','{$subjectarea}','{$profname}',
		'{$email}',	'{$projdesc}','{$quals}','{$hours}','{$credits}','{$credithours}',
	'{$status}','{$DPs}','{$websites}', '{$date}')";
	
/*$parameters = array($projtitle,$projlocation,$subjectarea,$profname,
					$email,	$projdesc,$quals,$hours,$credits,$credithours,
					$status,$DPs,$websites, $date); 
$query=odbc_prepare($dbconnect, $SQL);
odbc_execute ($query, $parameters); */
odbc_exec($dbconnect, $SQL);
odbc_close($dbconnect);

Open in new window

SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lilyyan
lilyyan

ASKER

well, i tried. it still shows same error: odbc_exec($dbconnect, $SQL);

myhost server has turned the magic_quotes_gpc, so by default, apostrophe will be escaped as \'
so i don't think i should use : str_replace("'","''",$projtitle).

am i right? thank you so much !!
OK, then the other question is, are actually connecting to the db? I don't see where you are setting the $dbconnect variable.
Avatar of lilyyan

ASKER

thank you for your reply!

about apostrophe sign, should i strip of magic_quotes_gpc and then use str_replace("'","''",$projtitle). ?

the connection is like the following.
<?php 
//Set up Variables
//connect to MS SQL 2005 Dev
$dbHost = "hostServer"; 
$dbUser = 'clientUser';
$dbPass = 'myPass';
$dsn= 'myDataSource';   //datasources
 
// Open DB connection
$dbconnect =odbc_connect($dsn, $dbUser, $dbPass, SQL_CUR_USE_ODBC)
     or DIE ("DATABASE FAILED TO RESPOND.");
 
?>

Open in new window