Monday, 6 June 2022
How to display Image in table cell using FPDF and Easy table
Friday, 20 May 2022
DataTables warning: table id=example - Invalid JSON response: How to Debug?
- Use
CTRL+SHIFT+I
(or navigate toCurrent Page Control > Developer > Developer Tools
. In the newer versions of Chrome, click the Wrench icon > Tools > Developer Tools.) to enable the Developer Tools. - From within the developer tools click on the
Network
button. - Click the
"XHR"
sub-button. - Initiate an
AJAX call
. - Double click the Name of the page under the
Network
button. It will open a new page with the details of the error.
Wednesday, 11 May 2022
Prevent caching data from database in PhP FullCalendar
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var events = [];
var eventsCache = {};
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
eventSources: [{
cache: false,
url: 'loadevent.php',
type: 'POST',
extraParams: function() { // Prevent caching data from database in fullcalendar
return {
cachebuster: new Date().valueOf()
};
},
}],
});
calendar.render();
calendar.refetchEvents();
});
</script>
Friday, 6 May 2022
How to configure PHP Calendar with events from database?
Download fullcalendar file from : https://github.com/
<link href='fullcalendar-5.10.2/lib/
<script src='fullcalendar-5.10.2/lib/
document.addEventListener('
var calendarEl = document.getElementById('
var calendar = new FullCalendar.Calendar(
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,
},
events: 'loadevent.php',
},
displayEventTime: false,
selectHelper:true,
weekNumbers: true,
navLinks: true, // can click day/week names to navigate views
nowIndicator: true,
weekNumbers: true,
dayMaxEventRows: true, // for all non-TimeGrid views
views: {
timeGrid: {
dayMaxEventRows: 6 // adjust to 6 only for timeGridWeek/timeGridDay
}
},
});
calendar.render();
});
</script>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 align="center" style=" padding: 3%;"> Calendar Heading</h1>
<div id='calendar'></div>
</div>
</div>
</div>
</body>
$stmt = $con->prepare(" SQL QUERY ");
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$data[] = array(
'id' => $row["No"],
'title' => $row["title"], // DB ATTRIBUTE NAME FOR TITLE
'end' => $row["DATE2"], // DB END DATE ENTRY in yy-mm-dd 00:00:00 format
'description' => $row[" Description "], // DB Description attribute
);
//result is in row
}
echo json_encode($data);
Tuesday, 3 May 2022
Warning: mysqli_query() expects parameter 1 to be mysqli, resource given
You are mixing mysqli and mysql extensions in the code, which will not work. mysqli has many improvements over the original mysql extension, so it is recommended to use mysqli .
Friday, 29 April 2022
Pre Populate jquery Token input textbox with PhP MySQLi Resultset
- Download jquery token input plugin from https://loopj.com/jquery-tokeninput/
- Extract the zip file and put jquery.tokeninput.js and token-input.css in the application root folder.
- Download the latest version of jquery.min.js
Monday, 25 April 2022
Export mysqli resultset as excel with nested table in PhP
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$con = mysqli_connect("localhost", "root", "", "tablename");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$output = '';
$stmt3 = $con->prepare("SELECT id,registrationid,name,email,mobile,nationality,state,district,gender from adv33");
$stmt3->execute();
$stmt3->bind_result($id, $registrationid, $name, $email, $mobile, $nationality, $state, $district, $gender);
$stmt3->store_result();
if ($stmt3->num_rows > 0) {
$output .= '
<table border="1">
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Nationality</th>
<th>State</th>
<th>District</th>
<th>Gender</th>
</tr>
';
while ($stmt3->fetch()) {
$output .= '
<tr>
<td>' . $name . '</td>
<td>' . $email . '</td>
<td>' . $mobile . '</td>
<td>' . $nationality . '</td>
<td>' . $state . '</td>
<td>' . $district . '</td>
<td>' . $gender . '</td>
</tr>';
$output .= '
<table border="1">
<tr>
<td><b>Post</b></td>
<td><b>Company</b></td>
<td><b>From Date</b></td>
<td><b>To Date</b></td>
<td><b>Scale of Pay</b></td>
';
$stmt4 = $con->prepare("SELECT slno,email,post,company,fromdate,todate,scale FROM adv33exp where email ='$registrationid'");
$stmt4->execute();
/* bind result variables */
$stmt4->bind_result($slno, $email, $post, $company, $fromdate, $todate, $scale);
$stmt4->store_result();
if ($stmt4->num_rows > 0) {
/* fetch value */
while ($stmt4->fetch()) {
$output .= '
<tr>
<td>' . $post . '</td>
<td>' . $company . '</td>
<td>' . $fromdate . '</td>
<td>' . $todate . '</td>
<td>' . $scale . '</td>
</tr>
';
}
}
}
$output .= '</table>';
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=Applicants.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $output;
}
?>
Sunday, 24 April 2022
How to get hidden field value in jquery?
JS Code
<script>
$(document).ready(function(){
var userid = $('#userid').val();
}
</script>
HTML Code
<input type="hidden" name="userid" id="userid" value="8"/>
Friday, 22 April 2022
Add dynamic rows in html table with Add, Edit, Delete feature in PHP and MySQLi
dynamic-table.php
action.php
Config.php
class dbConfig {
protected $serverName;
protected $userName;
protected $password;
protected $dbName;
function dbConfig() {
$this -> serverName = 'localhost';
$this -> userName = 'root';
$this -> password = "";
$this -> dbName = "employee";
}
}
?>
Employee.php
<?php require('config.php'); class Employee extends Dbconfig { protected $hostName; protected $userName; protected $password; protected $dbName; private $empTable = 'employment'; private $dbConnect = false; public function __construct(){ if(!$this->dbConnect){ $database = new dbConfig(); $this -> hostName = $database -> serverName; $this -> userName = $database -> userName; $this -> password = $database ->password; $this -> dbName = $database -> dbName; $conn = new mysqli($this->hostName, $this->userName, $this->password, $this->dbName); if($conn->connect_error){ die("Error failed to connect to MySQL: " . $conn->connect_error); } else{ $this->dbConnect = $conn; } } } public function employeeList(){ $sqlQuery = "SELECT * FROM ".$this->empTable." "; $result = mysqli_query($this->dbConnect, $sqlQuery); $employeeData = array(); while( $employee = mysqli_fetch_assoc($result) ) { $empRows = array(); $empRows[] = $employee['post']; $empRows[] = $employee['company']; $empRows[] = $employee['type']; $empRows[] = $employee['fromdate']; $empRows[] = $employee['todate']; $empRows[] = $employee['scale']; $empRows[] = $employee['gross']; $empRows[] = '<button type="button" name="update" id="'.$employee["id"].'" class="btn btn-warning btn-xs update">Update</button>'; $empRows[] = '<button type="button" name="delete" id="'.$employee["id"].'" class="btn btn-danger btn-xs delete" >Delete</button>'; $employeeData[] = $empRows; } $output = array( "draw" => intval($_POST["draw"]), "data" => $employeeData ); echo json_encode($output); } public function getEmployee(){ if($_POST["empId"]) { $sqlQuery = " SELECT * FROM ".$this->empTable." WHERE id = '".$_POST["empId"]."'"; $result = mysqli_query($this->dbConnect, $sqlQuery); $row = mysqli_fetch_array($result, MYSQLI_ASSOC); echo json_encode($row); } } public function updateEmployee(){ if($_POST['empId']) { $updateQuery = "UPDATE ".$this->empTable." SET userid = '".$_POST["userid"]."', post = '".$_POST["post"]."', company = '".$_POST["company"]."', type = '".$_POST["type"]."', fromdate = '".$_POST["fromdate"]."' , todate = '".$_POST["todate"]."' , scale = '".$_POST["scale"]."', gross = '".$_POST["gross"]."' WHERE id ='".$_POST["empId"]."'"; $isUpdated = mysqli_query($this->dbConnect, $updateQuery); } } public function addEmployee(){ $insertQuery = "INSERT INTO ".$this->empTable." (userid, post, company, type, fromdate, todate,scale, gross) VALUES ('".$_POST["userid"]."','".$_POST["post"]."', '".$_POST["company"]."', '".$_POST["type"]."', '".$_POST["fromdate"]."', '".$_POST["todate"]."', '".$_POST["scale"]."', '".$_POST["gross"]."')"; $isUpdated = mysqli_query($this->dbConnect, $insertQuery); } public function deleteEmployee(){ if($_POST["empId"]) { $sqlDelete = " DELETE FROM ".$this->empTable." WHERE id = '".$_POST["empId"]."'"; mysqli_query($this->dbConnect, $sqlDelete); } } } ?>
employee.sql
Tuesday, 19 April 2022
Fatal error: Cannot redeclare Function() in PhP
Solution
1. Don't declare a function inside a loop. Declare before them.
You should include the file (wherein that function exists) only once. So instead of
include ("function.php");
use include_once("function.php");
Monday, 18 April 2022
Integrate TinyMCE Editor in PhP
1. Download the latest version of TinyMCE SDK
https://www.tiny.cloud/get-tiny/
2. Extract the folder [tinymce] and put in your application root folder.
eg: C:\xampp\htdocs\tinymcedemo\tinymce [tinymcedemo is the root folder]
3. Create a php file "test.php" and place the below code
<html>
<head>
<script src="tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: '#mytextarea'
});
</script>
</head>
<body>
<h1>TinyMCE </h1>
<form method="post">
<textarea id="mytextarea"></textarea>
</form>
</body>
</html>
How to disable phpinfo() in a hosting environment?
Login to server WHM as a root user
Edit the php.ini file. Add below lineFriday, 15 April 2022
Fatal error: Cannot pass parameter by reference in PHP
Fatal error: Cannot pass parameter by reference in PHP.
The error is with 'test'
in the bind_param
call.
All parameters to bind_param
must be passed by reference. A string is a primitive value, and cannot be passed by reference.
You can fix this by creating a variable and passing that as a parameter instead:
$testvar="test";
Enable or disable the "Powered by TinyMCE" branding.
Tinymce branding property allow you to enable or disable the "Powered by TinyMCE" branding.
tinymce.init({
selector: 'textarea',
branding: false
});
Thursday, 14 November 2019
Adding Excel export button hides/removes the Page Length Dropdown in Data Tables
"dom": '<"top"Bf>rt<"bottom"lip><"clear">'
Complete Code
<script>
$(document).ready(function () {
$('#example').DataTable( {
"processing": true,
"lengthMenu": [[25, 50, -1], [ 25, 50, "All"]],
"dom": '<"top"Bf>rt<"bottom"lip><"clear">',
"serverSide": true,
"ajax": "server_processing.php"
} );
});
</script>
Thursday, 24 April 2014
Add image/logo in browser tab for website
Sunday, 27 October 2013
Keep checkbox checked after submit refresh in PHP
<?php
if (isset($_POST['number']))
{
foreach ($_POST['number'] as $selectednumber)
$selected[$selectednumber] = "checked";
}
?>
<form action="" method="post">
<input type="checkbox" name="number[]" <?php echo $selected['one'] ?> value="one" />one<br />
<input type="checkbox" name="number[]" <?php echo $selected['two'] ?> value="two" />two<br />
<input type="checkbox" name="number[]" <?php echo $selected['three'] ?> value="three" />three<br />
<input type="checkbox" name="number[]" <?php echo $selected['four'] ?> value="four" />four<br />
<input type="submit" name="Submit" value="Preview" />
</form>
Friday, 25 October 2013
Multiple submit button in a single form in PHP
<input type="submit" name="save" value="Submit 1">
<input type="submit" name="cancel" value="Submit 2">
</form>
<?php
if (isset($_POST['save'])) {
// code
}
else if (isset($_POST['cancel'])) {
// code
}
?>
Friday, 4 October 2013
Fatal error: Call to undefined function http_redirect() : Fixed
http_redirect()
function, below error came up:Fatal error: Call to undefined function http_redirect() in location.
Add the below function in your php page
/**
* redirect to a specific URL
* @param $url
*/
function redirect($url)
{
if (!headers_sent())
{
//If headers not sent yet... then do php redirect
header('Location: '.$url); exit;
}
else
{
//If headers are sent... do javascript redirect...
//if javascript disabled, do html redirect.
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>'; exit;
}
}
then call the above function to the page you wish the redirect to happen on
eg: redirect("redirect.php");