Search code examples
phpsql-server-2008r2-express

how to fix this below error?


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";
    }
?>

Solution

  • 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.
    }