Failed to open error in libchart library in php - php

I'm using Libchart library in my project to generate graphs. I'm trying to execute example in libchart but I'm getting following error.
imagepng(generated/demo1.png): failed to open stream: No such file or
directory in
C:\xampp\htdocs\test\fileupload\libchart\classes\view\plot\Plot.php on
line 284
this is my code
include "libchart/classes/libchart.php";
$chart = new VerticalBarChart(500, 250);
$dataSet = new XYDataSet();
$dataSet->addPoint(new Point("Jan 2005", 273));
$dataSet->addPoint(new Point("Feb 2005", 321));
$dataSet->addPoint(new Point("March 2005", 442));
$dataSet->addPoint(new Point("April 2005", 711));
$chart->setDataSet($dataSet);
$chart->setTitle("Monthly usage for www.example.com");
$chart->render("generated/demo1.png");
when I change the last line of code to $chart->render(); then it opens binary format in my browser.
Could any one please help me to solve this error?

this is my complete code
<?php
include "libchart/classes/libchart.php";
class fileupload
{
var $htmlID_type = "type";
var $type_uploadfile = 0;
var $type_generategraphs = 1;
var $content_html = "";
function __construct()
{
$this->__switch();
$this->__print();
}
function __switch()
{
enter code here
$this->param_type = $this->getParamType();
switch ($this->param_type)
{`enter code here`
case $this->type_uploadfile :
$this->selectFileUplaod ();
break;
case $this->type_generategraphs :
$this->generateGraphs();
break;
}
}
function __print()
{
print <<<HEREDOC
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
body{
margin-left:20%;
margin-right:20%;
margin-top:50px;
}
table, td, th
{
border:1px solid black;
}
th
{
background-color:#00BFFF;
color:white;
}
</style>
</head>
<body>
{$this->content_html}
</body>
</html>
HEREDOC;
}
function getParamType()
{
if (isset ( $_GET [$this->htmlID_type] ))
{
return $_GET [$this->htmlID_type];
}
else
return $this->type_uploadfile;
}
function selectFileUplaod()
{
$con=mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT
income_id,
month,
paint_cost,
parts_cost,
repair_cost,
excess_Suspense,
sublet,
remove_refit_cost
FROM income");
echo "<h3>Bundamba Income</h3>";
echo "<table>
<tr>
<th>Paint</th>
<th>Parts</th>
<th>Remove Refit Cost</th>
<th>Repair</th>
<th>Excess Suspense</th>
<th>Sublet</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td width=100>" . $row['paint_cost'] . "</td>";
echo "<td width=100>" . $row['parts_cost'] . "</td>";
echo "<td width=100>" . $row['remove_refit_cost'] . "</td>";
echo "<td width=100>" . $row['repair_cost'] . "</td>";
echo "<td width=100>" . $row['excess_Suspense'] . "</td>";
echo "<td width=100>" . $row['sublet'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<br>";
$result1 = mysqli_query($con,"SELECT
cost_of_saleID , paint_liquid ,
paint_consumables,
workshop_consumables,
parts_purchased,
wages_paintshop,
wages_workshop,
suplier_discount,
sublet_cost
FROM cost_of_sale
LIMIT 0 , 30");
echo "<h3>Bundamba cost of sale</h3>";
echo "<table>
<tr>
<th>Paint Consumables</th>
<th>Paint Liquid</th>
<th>Parts Purchased</th>
<th>Workshop Consumables</th>
<th>Wages - Paintshop</th>
<th>Wages - Workshop</th>
<th>Supplier Discounts</th>
<th>Sublets Costs</th>
</tr>";
while($row = mysqli_fetch_array($result1))
{
echo "<tr>";
echo "<td>" . $row['paint_consumables'] . "</td>";
echo "<td>" . $row['paint_liquid'] . "</td>";
echo "<td>" . $row['parts_purchased'] . "</td>";
echo "<td>" . $row['workshop_consumables'] . "</td>";
echo "<td>" . $row['wages_paintshop'] . "</td>";
echo "<td>" . $row['wages_workshop'] . "</td>";
echo "<td>" . $row['suplier_discount'] . "</td>";
echo "<td>" . $row['sublet_cost'] . "</td>";
echo "</tr>";
}
echo "</table>";
$this->content_html = <<<End_Of_String
<FORM action="uploadFile.php?{$this->htmlID_type}={$this->type_generategraphs}" method="POST" />
<input type="submit" value="Income vs Cost" style="margin-top:20px">
<input type="submit" value="Income vs Cost Ratio" style="margin-top:20px">
</FORM>
End_Of_String;
// mysqli_close($con);
}
function generateGraphs()
{
echo getcwd();
print "rrrrr";
header("Content-type:image/png");
$chart = new VerticalBarChart(500, 250);
$dataSet = new XYDataSet();
$dataSet->addPoint(new Point("Jan 2005", 273));
$dataSet->addPoint(new Point("Feb 2005", 321));
$dataSet->addPoint(new Point("March 2005", 442));
$dataSet->addPoint(new Point("April 2005", 711));
$chart->setDataSet($dataSet);
$chart->setTitle("Monthly usage for www.example.com");
$chart->render("demo/generated/demo1.png");
readfile("demo/generated/demo1.png");
// $im = imagecreatefrompng("demo/generated/demo1.png");
// header('Content-Type: image/png');
//imagepng($im);
//imagedestroy($im);
}
}
$obj = new fileupload();
?>

I got the same error now when trying to plot the piechart using LibChart library. The problem is that you would not have created a folder named 'generated' in your current folder.. but the name given for the image is generated/demo1.png which says that generated is a folder containing the file "demo1.png". So, just give 'demo1.png' instead of 'generated/demo1.png' and try running the snippet.. I got the output just now!!

Related

Does not print everything from sql database

I am trying to build a forum for my school project. Now i want to get the data out of my database so i can print it and people can see and react to it. Now i have the problem that it only print the commenters post and not the creators post. I will ad some picture and the code so you guys can undestand. (PS. i have a form on the previous page where you can search)
Database
Website
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./style.css">
<title><?php echo $_GET["search"];?></title>
</head>
<body>
<?php
//navbar
include "./include/nav.php";
//database connection
include "./include/conn.php";
$search = $_GET["search"];
if($search == ""){
// if empty return to index
echo "
<script>alert('thread does not exist')</script>
<script>window.location = './index.php'</script>
";
} else {
//check if data exist
$sql = "SELECT thread, post, username, status FROM post WHERE thread = ? ";
$query = $conn->prepare($sql);
$query->execute(array($search));
$data = $query->fetch();
if($data){
// print data if exist
echo "<div class='padding'>";
foreach ($query as $test) {
echo "<tr>";
echo "<td>" . $test["thread"] . "</td>";
echo "<td>" . $test["post"] . "</td>";
echo "<td>" . $test["username"] . "</td>";
echo "<td>" . $test["status"] . "</td>";
echo "</tr>" . "</br>";
}
echo "<button onclick='comment()'>Comment</button>";
echo "</div>";
echo "<div id='test'>";
} else {
// if data does not exist return to index
echo "
<script>alert('thread does not exist')</script>
<script>window.location = './index.php'</script>
";
}
}
?>
<script>
// if comment btn is pressed save thread name and send to comment.php
function comment() {
document.getElementById("test").innerHTML =
"<?php
session_start();
$_SESSION['thread'] = $data['thread'];
?>";
window.location.assign("./comment.php")
}
</script>
</body>
</html>
I never used the data that i got out of the database. I should have printed it like this:
if($data){
// print data if exist
echo "<div class='padding'>";
foreach ($data as $test) {
echo "<tr>";
echo "<td>" . $test["thread"] . "</td>";
echo "<td>" . $test["post"] . "</td>";
echo "<td>" . $test["username"] . "</td>";
echo "<td>" . $test["status"] . "</td>";
echo "</tr>" . "</br>";
}
echo "<button onclick='comment()'>Comment</button>";
echo "</div>";
echo "<div id='test'>";
} else {
// if data does not exist return to index
echo "
<script>alert('thread does not exist')</script>
<script>window.location = './index.php'</script>
";
}
}

Select url from database into php variable

<?php
try{
include("dbconnectie.php");
$query = $db->prepare("SELECT * FROM shop WHERE id_img = '3'");
$query->execute();
$result = $query->fetchALL(PDO::FETCH_ASSOC);
$image = $result['img_url'];
echo "<table>";
foreach($result as &$data) {
echo "<tr>";
echo "<td>" . $data["brand"] . "</td>";
echo "<td>" . $data["model"] . "</td>";
echo "<td>" . $data["cond"] . "</td>";
echo "<td>" . $data["price"] . "</td>";
echo '<img src="data:image/png;base64,'.base64_encode( $data["image"] ).'"/>';
echo "</tr>";
}
echo "</table>";
} catch(PDOException $e) {
die("Error!: " . $e->getMessage());
}
?>
<html>
<body>
<a src='<?php echo $image; ?>' border='0'></a>
</body>
</html>
in line 7 u can see that i'm trying to define $image as the url that's saved in the database so i could use it all the way at the bottom to project it as an image.

How to attach image in doc file using CakePhp?

Here, I want to add a image a doc file header. I'm using Cakephp 2. Help me to add a image in header of doc file.
When I try to add it is showing some problem. I try to use from my directory of cakephp and I also try to using image link.
public function admin_get_member_detail() {
if ($this->request->is('post')) {
$data = $this->request->data;
$this->loadModel('Organization');
$this->loadModel('VoteResult');
$this->loadModel('VoteReResult');
$orgData = $this->Organization->find('first', array('conditions' => array('Organization.member_id' => $data['Designation']['member_id'])));
//$image = $this->Html->image('ica-logo.png', array('style' => 'height:100px;width:500px;border: thin solid black; border-radius:5px;'));
$VoteResult = $this->VoteResult->query('select vote.election_id,vote.candidate_id,vote.election_phase,candidate.name,candidate.id,candidate.designation,designation.id,designation.name,sum(vote.vote_val) as total from tbl_vote_result as vote join tbl_candidate as candidate on candidate.id = vote.candidate_id join tbl_designation as designation on designation.id = candidate.designation
where organization_id =' . $orgData['Organization']['id'] . ' group by vote.candidate_id ORDER BY total DESC ');
$ReVoteResult = $this->VoteReResult->query('select vote.election_id,vote.candidate_id,vote.organization_id,vote.election_phase,vote.candidate_deg,candidate.name,candidate.id,candidate.Organization,designation.id,designation.name,sum(vote.vote_val) as total1 from tbl_re_vote_result as vote join tbl_candidate as candidate on candidate.id = vote.candidate_id join tbl_designation as designation on designation.id = vote.candidate_deg
where vote.organization_id = ' . $orgData['Organization']['id'] . ' group by vote.candidate_id ORDER BY total1 DESC');
//pr($ReVoteResult);die;
if (!empty($VoteResult)) {
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=" . $orgData['Organization']['name'] . '_' . date("H:i:s") . '.doc');
$now_date = date('d-m-Y H:i');
echo "<html>";
echo "<head>";
//echo ".<?= $this->Html->image('ica-logo.png', array('style' => 'height:100px;width:500px;border: thin solid black; border-radius:5px;'));
echo "<img src='https://en.facebookbrand.com/wp-content/uploads/2016/09/facebook-live-brc-preview2.png'/>\n";
echo "</head>";
echo "<body>";
echo "<div style='font-size:18px;font-weight:bold;'>" . $orgData['Organization']['name'] . "</div>\n";
echo "<div>Date:$now_date</div>";
echo "<br>";
echo "<br>";
echo "<table align='center' style='text-align:center' border='1' cellpadding='0' cellspacing='0'>";
echo "<tr><td colspan='3'>For Board Member</td></tr>";
echo"<tr><th>Sl No.</th><th>Candidate Name</th><th>Total Vote</th></tr>";
foreach ($VoteResult as $key => $res) {
echo "<tr>";
echo "<td>" . ++$key . "</td>";
echo "<td>" . $res['candidate']['name'] . "</td>";
echo "<td>" . $res[0]['total'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<br>";
echo "<table align='center' style='text-align:center' border='1' cellpadding='0' cellspacing='0'>";
echo "<tr><td colspan='3'>For President</td></tr>";
echo"<tr><th>Sl No.</th><th>Candidate Name</th><th>Total Vote</th></tr>";
echo "</table>";
echo "</body>";
echo "</html>";
die;
} else {
$this->Session->setFlash(__('Member Id Invalid'));
$this->redirect($this->referer());
}
}
}

PHP, trying to make row ID's work

So I basically been coding this quick stat shower for my game server, but I want it to ID numbers.
<html>
<head>
<meta charset="utf-8">
<title>ExileMod Stats</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<?php
$con=mysqli_connect("******","******","******","******"); //server address, username, password, dbname
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//check order ascending or descending
if (isset($_GET["order"])) {
$sort = $_GET["order"];
if ($_GET["order"] == "asc"){
$sort = "desc";
$order = "asc";
}
else{
$sort = "asc";
$order = "desc";
}
}
//check filter
if (isset($_GET["name"])) {
$name = $_GET["name"];
}
else {
$name = "name";
}
$list=array('name', 'money', 'score', 'kills', 'deaths', 'uniform', 'vest', 'last_updated_at');
if (in_array($name,$list))
{
//variable ok
}
else
{
$name = "name";
}
$query = mysqli_query($con,"SELECT * FROM account a INNER JOIN player p ON a.uid = p.account_uid ORDER BY a.$name $order");
?><!--//echo "<table border='1'>-->
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<table class="table">
<tr>
<?php echo "<th>Player Name</th>";?>
<?php echo "<th>Money</th>";?>
<?php echo "<th>Score</th>";?>
<?php echo "<th>Kills</th>";?>
<?php echo "<th>Deaths</th>";?>
<?php echo "<th>Uniform</th>";?>
<?php echo "<th>Vest</th>";?>
<?php echo "<th>Last Updated</th>";?>
</tr>
<!--//";-->
<?php
while($row = mysqli_fetch_array($query))
{
?><tr class="danger"><?php
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['money'] . "</td>";
echo "<td>" . $row['score'] . "</td>";
echo "<td>" . $row['kills'] . "</td>";
echo "<td>" . $row['deaths'] . "</td>";
echo "<td>" . $row['uniform'] . "</td>";
echo "<td>" . $row['vest'] . "</td>";
echo "<td>" . $row['last_updated_at'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
© HeroesOfGaming 2016 - 2017
</div>
</body>
</html>
So what I am trying to do is put numbers so it counts 1 2 3 4 5 6 7 to however many players are selected from the database? Hopefully this makes sense.
You can do like this
<?php
$i = 0; // <--- Added this
while($row = mysqli_fetch_array($query))
{
$i++; // <--- Added this
?><tr class="danger"><?php
echo "<td>". $i . "</td>"; // <--- Added this
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['money'] . "</td>";
echo "<td>" . $row['score'] . "</td>";
echo "<td>" . $row['kills'] . "</td>";
echo "<td>" . $row['deaths'] . "</td>";
echo "<td>" . $row['uniform'] . "</td>";
echo "<td>" . $row['vest'] . "</td>";
echo "<td>" . $row['last_updated_at'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>

If functions per $row in a table

I have a table that shows me data from a call flow.
I need the Data from this table to be manipulated per row in such a way that all the values of my table, which are being looked up from my DB, (which are now in code) will be translated into a text value. Let me show U and explain:
My Table:
<?php
include_once "Connect2Martijn1.php";
?>
<link rel="stylesheet" href="CSSMartijn1.css">
</link>
<head>
<meta charset="iso-8859-1">
<meta name="description"content="VoizXL ">
<meta name="keywords"content="VoizXL ">
<meta name="author"content="Kenn Lo-A-Tjong">
</meta>
<title>Call Flow</title>
</head>
<fieldset>
<article class="rondehoeken">
<header>
<div class="streep1"></div>
<div class="streep2"></div>
<div class="streep3"></div>
<div class="streep4"></div>
<div class="streep5"></div>
<h1 id="artikel-titel" >Call Flow</h1>
</header>
<div id="artikel-container">
<table class="table 1">
<thead>
<title>Call Flow</title>
<meta charset = "UTF-8" />
<style type = "text/css">
table, td, th {
border: 1px solid black;
}
</style>
</thead>
<tbody>
<?php
$con=mysqli_connect("localhost","root","","voizxl_wachtrij");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Callflow");
echo "<table border='0'>
<tr>
<th>Nummer</th>
<th>Naam</th>
<th>Status</th>
<th>Time</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . $row['statusAnswered'] . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Example of (how I want to be) Translating the Data:
<?php
if ($row['statusAnswered'] ="NULL")
{
echo "Not Answered!";
}
else
{
echo "Answered!";
}
?>
What I want to Achieve is for eg. that the value in this table from $row['statusAnswered'] will be displayed in text as "Answered or Not Answered" if the Value of this row in the DB is NULL or Not...
How do I do this?
Right now I can only achieve to have 1 echo under the table saying Answered :S
No Idea how to put it per $row.
while($row = mysqli_fetch_array($result))
{
if (!isset($row['statusAnswered']))
{
$answered = "Not Answered!";
}
else
{
$answered = "Answered!";
}
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . $answered . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
if ($row['statusAnswered'] =="NULL"||$row['statusAnswered'] =="Null" || $row['statusAnswered'] =="null" || $row['statusAnswered'] =="")
{
echo "<td>Not Answered!</td>";
}
else
{
echo "<td>Answered!</td>";
}
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<table border='0'>
<tr>
<th>Nummer</th>
<th>Naam</th>
<th>Status</th>
<th>Time</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . ($row['statusAnswered']=='NULL'?'Not Answered!':'Answered!') . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
You could use;
$checkstatus = if($row['statusAnswered'] = NULL) { echo "Not Answered!"; } else {echo "Answered!";};
then call that by replacing;
echo "<td>" . $row['statusAnswered'] . "</td>";
with;
echo "<td>{$checkstatus}</td>"

Categories