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