-3

connected successfully..

Notice: Undefined index: blog_id in C:\xampp\htdocs\lendkarma\dashboard\editpost.php on line 3 Notice: Undefined index: empid in C:\xampp\htdocs\lendkarma\dashboard\editpost.php on line 5 Notice: Undefined index: blog_title in C:\xampp\htdocs\lendkarma\dashboard\editpost.php on line 6 Notice: Undefined index: blog_content in C:\xampp\htdocs\lendkarma\dashboard\editpost.php on line 7

Notice: Undefined index: blog_author in C:\xampp\htdocs\lendkarma\dashboard\editpost.php on line 8

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

<?php

include_once 'config/db_config.php';

$blogid = $_REQUEST['blog_id'];

//$password = $_POST['optionsRadios'];

$empid=$_REQUEST['empid'];

$blog_title=$_REQUEST['blog_title'];

$blog_content=$_REQUEST['blog_content'];

$blog_author=$_REQUEST['blog_author'];

//$status=$_REQUEST['status'];

if($userconnection)
    {  
       $query = "UPDATE blogs SET empid='$empid',blog_title='$blog_title',blog_content='$blog_content',blog_author='$blog_author' WHERE blog_id = $blogid";
       echo $query;
       $rs = odbc_exec($userconnection,$query);
    }
  else
    {
        echo "something went wrong";
    }
?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • What about the code? – lingo Jul 31 '15 at 08:58
  • possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Epodax Jul 31 '15 at 08:58
  • undefind index means that field is not set,use isset to check it – Mihai Jul 31 '15 at 08:58

3 Answers3

0

To fix the error you can query if the variable exist before you use it. You can use the function isset or empty to check if the variable exist.

Heres a example:

if(isset($array['empid'])) {
    // do it
} else {
    // dont do it because the variable dont exist.
}
Tobias
  • 653
  • 4
  • 12
0

The reason behind this error is the values are not assigned to the variables.

If it affects your output,try to fix the variable assignments correctly.

If it does not affect your output means just off the errors by calling error_reporting(0) in the top of your script.

ManiMuthuPandi
  • 1,594
  • 2
  • 26
  • 46
0

I assume this is not all the script and that you have a <form> later on in the script that this code is supposed to process.

However the first time the script is run there will be no data i.e. nothing in the $_POST or $_GET arrays, as the form has not been posted it has just been launched for the first time.

You need to wrap this code in something that tests if the form is being run for the first time or being sent by the user who pressed the submit button

As you are using $_REQUEST its difficult to know what you are actually using so I will test for both GET and POST.

So something like this

if ($_SERVER["REQUEST_METHOD"] == 'POST' || $_SERVER["REQUEST_METHOD"] == 'GET') {
    // The user must have presses the submit button

    // you should check for valid contents of all these fields first
    $blogid       = isset($_REQUEST['blog_id'])      ? $_REQUEST['blog_id']      : '';
    $empid        = isset($_REQUEST['empid'])        ? $_REQUEST['empid']        : '';
    $blog_title   = isset($_REQUEST['blog_title'])   ? $_REQUEST['blog_title']   : '';
    $blog_content = isset($_REQUEST['blog_content']) ? $_REQUEST['blog_content'] : '';
    $blog_author  = isset($_REQUEST['blog_author'])  ? $_REQUEST['blog_author']  : '';

    if (isset($blogid,$userconnection)) {  
       $query = "UPDATE blogs SET 
                    empid='$empid',
                    blog_title='$blog_title',
                    blog_content='$blog_content',
                    blog_author='$blog_author' 
                 WHERE blog_id = $blogid";

       $rs = odbc_exec($userconnection,$query);
       if ( ! $rs ) {
        echo odbc_errormsg($userconnection);
       }
    } else {
        echo "Please fill all the fields";
    }
}

// now comes the html for the page

Now you will only attempt to use these variables and the database update that depends upon them if they actuall exist.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Warning: odbc_exec(): SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data would be truncated., SQL state 22001 in SQLExecDirect in C:\xampp\htdocs\lendkarma\dashboard\editpost.php on line 16 [Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data would be truncated. – Binny Yogesh Sg Jul 31 '15 at 11:48
  • Maybe thats because I set the default values of all the fields to `NULL` maybe if we change that to an empty string it would be better. See changes. Either that or you have one of the database fields set to a small size and are passing a larger string that it can hold. – RiggsFolly Jul 31 '15 at 12:06
  • 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:55
  • echo the query after you create `$sql` and before the `odbc_exec` This is debugging 101. – RiggsFolly Aug 01 '15 at 18:54