0

Warning : odbc_exec(): SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'to'., SQL state 37000 in SQLExecDirect in C:\xampp\htdocs\lendkarma\dashboard\viewpost.php

<?php
if($userconnection)
    {
       $sql_result="INSERT into blogs_new(empid,blog_title,status,blog_author) VALUES ($empid,$title,$a,$status,$author)";
       echo $sql_result;
       $res=odbc_exec($userconnection,$sql_result);
     // $res = odbc_prepare($userdatabase,"INSERT INTO t_blogs (empid,blog_title,blog_content,status,blog_author) VALUES ($empid,$title,$a,$status,$author)");
    }
    else
    {
       echo "connection error";
    }
?>
Saty
  • 22,443
  • 7
  • 33
  • 51

2 Answers2

-1

Your values need quotes around them:

$sql_result="INSERT into blogs_new(empid,blog_title,status,blog_author) VALUES ('$empid','$title','$a','$status','$author')";
Evadecaptcha
  • 1,403
  • 11
  • 17
  • connected successfully.. Warning: odbc_exec(): SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '='., SQL state 37000 in SQLExecDirect in C:\xampp\htdocs\lendkarma\dashboard\action\update_post.php on line 30 [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '='. – Binny Yogesh Sg Aug 01 '15 at 07:56
  • how to fix this issues plz help me – Binny Yogesh Sg Aug 01 '15 at 07:57
-1

I think you should add some apostrophe around your string type of value in your sql query string. Something like this.

$sql_result="INSERT into blogs_new(empid,blog_title,status,blog_author) VALUES ('".$empid."','".$title."','".$a."','".$status."','".$author."')";
Sigee
  • 362
  • 2
  • 11
  • Warning: odbc_exec(): SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert the value NULL into column 'blog_id', table 'lend_user.dbo.blog'; column does not allow nulls. INSERT fails., SQL state 23000 in SQLExecDirect in C:\xampp\htdocs\lendkarma\dashboard\viewpost.php – Binny Yogesh Sg Jul 31 '15 at 06:52
  • Maybe it is because your SQL table has a blog_id column, that is not auto increment but not allows null and the query dont set that value. Try to change the column to auto increment. – Sigee Jul 31 '15 at 06:59
  • Update blogs SET empid='',blog_title='',blog_content='',blog_author='' WHERE blog_id = Warning: odbc_exec(): SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '='., SQL state 37000 in SQLExecDirect in C:\xampp\htdocs\lendkarma\dashboard\editpost.php on line 16 – Binny Yogesh Sg Jul 31 '15 at 08:43
  • I mean the table definition not the record. Please check this. http://stackoverflow.com/questions/6084572/sql-server-how-to-set-auto-increment-after-creating-a-table-without-data-loss – Sigee Jul 31 '15 at 09:39