I am making a textEditor website just for fun for me and I got most of what I am going to do down. But now, I am wondering I am having issue with a transfer of data by _GET method in php and won't write to my files if it is < (<). It has to be < for some odd reason. Is there an easy method to override this when it transfer it? I could find some way, but wanted to know if there was a simple way.
EDITOR FILE:
<html>
<head>
<title>Web Editor</title>
<link href="controller.css" rel="stylesheet"/>
<script type="text/javascript" src="script/editor.js"></script>
</head>
<body>
<div class="platform">
<div class="head"><div class="file"><p>File: <div id="file">hello.html</div></p></div></div>
<div class="hotbar"><img src="images/save.png" class="hotbarImage" onClick="save()" />
</div>
<div class="editor"><div contenteditable="true" style="height:100%; overflow:scroll;" id="editPad" ></div></div>
</div>
</body>
</html>
PHP FILE:
<?php
$dir = $_GET['dir'];
$data = $_GET['data'];
$f = fopen($dir,"w");
fwrite($f,$data);
fclose($f);
?>
SAVE JS FILE:
function save() {
var dir = document.getElementById("file").innerHTML;
var data = document.getElementById("editPad").innerHTML;
window.location = "save.php?dir="+dir+"&data="+data;
}
It's not complete just cause I started today, but was working on some of the basics functions.
html_entity_decode('<')
Related
I'm getting weird results when trying to kind of make a "templating engine". Basically, I want to be able to use PHP variables that contain data from an SQL database.
What happens is that everything works properly with the PHP side, what does not is the page that needs to display this information (index.php).
I'm working on a way to get the website's name from the sql database, so I have something like that on my index:
<?php
include ('php/data/sitename.php');
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $sitename; ?> - Home</title>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<div class="container">
<!-- HEADER: Navbar -->
<?php $navbar; ?>
<!-- MAIN: Index Page contents -->
<?php $page_index ?>
<!-- FOOTER: Footer -->
<?php $footer; ?>
<?php $sitename; ?>
</div>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
</body>
</html>
This variable comes from a file (that has been included) called sitename.php, with the following code:
<?php
include ('../db.php');
$sql = "SELECT id, sitename FROM GeneralData";
$getname = mysqli_query($conn, $sql);
if ($getname->num_rows > 0) {
while($row = $getname->fetch_assoc()) {
$sitename = $row['sitename'];
echo $sitename;
}
}
?>
Yes, I used echo $sitename;, I know it wont echo the actual data, but I did it to test some things, and here are the results:
Including the file sitename.php to index.php will do nothing, it would be like if it did not exist. However, if I write "echo "123";" on it, it will echo 123 on index. What does not work is what I need.
If I go to sitename.php directly, it will simply output the correct SQL value I requested because I told it to echo (as I stated before). But, it wont work in index, it will simply not work.
Also, I'll leave my project structure here. It might help.
What can I do?
Thanks in advance!
try set GLOBAL for sitename
GLOBAL $sitename;
or
GLOBALS['sitename'];
$sitename = ...
EDIT
try use
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/yourpath/yourfile.php";
include_once($path);
I have two DIVs which are floating side by side correctly but after embedding the php code as below, the whole page will not show anything. Even When I remove the php code, the page will not show again. The code below is for the div that floats right.
<div style="float:right;">
<?php
echo "<div>
<head>
<link rel='stylesheet' type='text/css' href='chatbox/style/cb_style.css'>
<script type='text/javascript' src='chatbox/ajax.js'></script>
<script type='text/javascript' src='chatbox/chatbox.js'></script>
</head>
<div>";
?>
<div id="container">
<div id="usersOnLine">
<div style="font-weight:bold;margin-top:35%;">Online Users</div>
<div style="height:82%;">
<?php
if (!empty($friends)) {
foreach ($friends as $friend) {
$friend_name = htmlentities($user['username'], ENT_NOQUOTES);
echo "<span>{$friend_name}</span>";
}
}
?>
</div>
<form method="post" action="">
<input type='text' placeholder='search' style='width:145px;'/><a href='#'><span class='glyphicon glyphicon-search'></span></a>
</form>
</div>
<div id="chat_search">
<un>
</div>
</div>
</div>
<div style="clear:both;"></div>
Since you are adding a <head> element into the DOM, you should remove that surrounding div and head and place that first chunk of php code inside your page's <head> section. The browser is getting confused when you introduce a new <head> element that way.
EDIT: to explain further, with a possible example...
You can add those new stylesheet and js entries into your head by appending them to your header include (assuming you are using an include for your main html header - in this example, we call it "header.php", since that's common)
<?php
$addme = '<link rel="stylesheet" type="text/css" href="chatbox/style/cb_style.css">
<script type="text/javascript" src="chatbox/ajax.js"></script>
<script type="text/javascript" src="chatbox/chatbox.js"></script></head>';
ob_start(); // start a buffer
include("header.php");
$contents = ob_get_contents(); // buffer the contents of header.php
ob_end_clean(); // end & clean the buffer
// replace the closing tag with the added stuff
echo str_replace('</head>', $addme, $contents);
?>
I have a SlickGrid set up, it is reading data from my database with PHP, my problem is arising when i try to save the data back to my database, I am trying to use JSON to give me an array that I can then use to write back to the database, i have see this thread explaining this:
Saving changes in SlickGrid
So I have the hidden form element in my code, and am using JSON to encode the data variable, the assign it to the data hidden input on the form, this form posts to a page called save_price.php, the trouble is when I print_r, or var_dump the data variable, I get null as an output, I think it might be something to do with how I am using PHP to add the content into the data variable, either that or I am doing something really obviously wrong, hopefully you can see what the problem is, there isn't a great deal of documentation online about retrieving/saving to a db with PHP, so I'm kinda stuck banging my head against the wall on this one, here's my code:
Ok so I found the problem, just incase anyone is struggling to get this all to work, here is the working code, it gets data from a database, then sends the changed data to another page for processing, it nees a little bit of refinements, that will happen once I've got it all implemented:
<?php
include("includes/check_session.php");
require_once('includes/functions.php');
require_once('includes/config.php');
$data = '';
$i = 0;
$query = "
SELECT * FROM `prices`";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$data .= '
data['.$i.'] = {
id: "'.$row['id'].'",
title: "'.$row['title'].'",
duration: "'.$row['duration'].'",
percentComplete: "'.$row['percentComplete'].'",
start: "'.$row['start'].'",
finish: "'.$row['finish'].'",
effortDriven: "'.$row['effortDriven'].'"
};
';
$i++;
echo $data;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<?php // include("includes/cms_head_scripts.php"); ?>
<link rel="stylesheet" href="css/slick.grid.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="css/smoothness/jquery-ui-1.8.5.custom.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="css/examples.css" type="text/css" media="screen" charset="utf-8" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript" src="js/jquery.json.js"></script>
</head>
<body>
<div id="content_cont">
<div id="main">
<div style="position:relative">
<div style="width:600px;">
<div id="myGrid" style="width:100%;height:500px;"></div>
</div>
</div>
pricing
</div><!-- #main -->
</div><!-- #content_cont -->
<script src="lib/firebugx.js"></script>
<script src="lib/jquery-ui-1.8.5.custom.min.js"></script>
<script src="lib/jquery.event.drag-2.0.min.js"></script>
<script src="slick.core.js"></script>
<script src="plugins/slick.cellrangeselector.js"></script>
<script src="plugins/slick.cellselectionmodel.js"></script>
<script src="slick.editors.js"></script>
<script src="slick.grid.js"></script>
<script type="text/javascript">
var grid;
var data = [];
var columns = [
{id:"title", name:"Title", field:"title", editor:TextCellEditor},
{id:"duration", name:"Duration", field:"duration", editor:TextCellEditor},
{id:"%", name:"% Complete", field:"percentComplete", editor:TextCellEditor},
{id:"start", name:"Start", field:"start", editor:TextCellEditor},
{id:"finish", name:"Finish", field:"finish", editor:TextCellEditor},
{id:"effort-driven", name:"Effort Driven", field:"effortDriven", editor:TextCellEditor}
];
var options = {
editable: true,
enableCellNavigation: true,
asyncEditorLoading: false,
autoEdit: true
};
$(function() {
<?php echo $data ?>
grid = new Slick.Grid($("#myGrid"), data, columns, options);
})
</script>
<form method="POST" action="save_price.php">
<input type="submit" value="Save">
<input type="hidden" name="data" value="">
</form>
<script type="text/javascript">
$(function() {
$("form").submit(
function() {
$("input[name='data']").val($.JSON.encode(data));
}
);
});
</script>
</body>
</html>
The Venkman debugger says this:
$("#aboutbox") is null
[Break On This Error] $("#aboutbox").hide();
But I don't know what to do to fix it!
It worked perfectly in HTML: http://leventhan.webfactional.com/static/
But when I moved it to PHP, it just stopped working.
Here's the index.php:
<?php
require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "Quick chat";
$params["nick"] = "guest".rand(1,1000); // setup the intitial nickname
$params['firstisadmin'] = true;
//$params["isadmin"] = true; // makes everybody admin: do not use it on production servers ;)
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["debug"] = false;
$chat = new phpFreeChat( $params );
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>phpFreeChat- Sources Index</title>
<link rel="stylesheet" title="classic" type="text/css" href="style/styles.css" />
<link rel="stylesheet" title="classic" type="text/css" href="style/content.css" />
<script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<SCRIPT type="text/javascript" src="oracle.js"></SCRIPT>
<script type="text/javascript">
// some google maps javascript code that works fine
</script>
</head>
<body>
<header>
<div id="aboutbox">
<br>
<p><strong>GeoChat is the perfect chat app to hatch your world domination plans. A place on the web where you can point to maps and chat at the same time.
A great way for teachers to teach and students to learn with an interactive map. </strong></p>
</div>
<div id ="nav">
<h1>GeoChat</h1><h2>Toggle backgroundChat HelpWhat's all this about?</h2>
</div>
</header>
<div id="map_canvas"></div>
<div class="content">
<?php $chat->printChat(); ?>
<?php if (isset($params["isadmin"]) && $params["isadmin"]) { ?>
<?php } ?>
</div>
<footer>
<p>❤ Made by <strong>Author</strong> with love.Go up ↑</p>
</footer>
</body></html>
Here's the live broken site: http://leventhan.webfactional.com/phpfreechat-1.3/
EDIT: Yeah, jQuery worked again when I commented out the chat app (phpFreeChat), this part:
<div class="content">
<?php $chat->printChat(); ?>
<?php if (isset($params["isadmin"]) && $params["isadmin"]) { ?>
<?php } ?>
</div>
And it turns out the problem is really because jQuery is conflicting with Prototype.js (phpFreeChat uses Prototype apparently.) The solution is to use:
jQuery.noConflict();
Edit: Oh, that is actually in your static version, so the static versions seems to be broken. Given this, it is impossible to tell what does not work in your PHP version.
I get an error
oracle.js:4 Uncaught ReferenceError: hide is not defined
The line where the error is thrown is
$("#aboutbox").live(hide());
Maybe you meant $("#aboutbox").hide(); ?
It worked!
It was jQuery and Prototype not getting along with each other.
Here's what I did:
add:
jQuery.noConflict();
change all occurences of:
$(document).ready(function(){
to:
jQuery(document).ready(function($) {
in my external js do a find and replace.
find: $
replace: jQuery (case sensitive).
I am seeing an error here (Chrome)
function showInDiv(text)
{
var sidediv = document.getElementById('content_window');
sidediv.innerHTML = text; // Cannot set property 'innerHTML' of null
}
What's content_window? I could not find it on the page
Hello friends a newbie question...
The Issue is like this:
I have a static HTML file and I want to import just a portion of that file into another page. How can I do that.
Example Code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Some title here</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div id="box-1">
<div class="block">
<!-- Some code here -->
</div>
</div>
<div id="box-2">
<div class="block">
<!-- Some code here -->
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="script.js"></script>
</body>
</html>
Now what I want is to read this HTML file and import just this bit:
<div id="box-1">
<div class="block">
<!-- Some code here -->
</div>
</div>
Is there a way of doing it?
Kindly help.
Even a PHP, jQuery, Ajax or any other solution will also do. Please help me.
You can use jQuery's load() to specify only a certain container to be loaded:
$('#targetdiv').load('static.html #box-1');
Here's a solution that differs from the others: It performs a one-time import of a section of content from a large number of static html files/pages (in case that was what you were wanting). I used it successfully to import about 700 pages from straight html to a cms database.
// get the pages you want to import
$pages = array('page1.html',
'page2.html',
'page3.html'
);
foreach($pages as $p) {
$url = 'http://yourDomain.com/' . $p;
// load the webpage
$file = file_get_contents($url);
if($file) {
list($before,$content) = explode('<body>',$file); // chop off beginning
unset($before);
list($content) = explode('<div id="box-2">',$content); // chop off end;
$resultArray[] = trim($content);
// or do it this way to keep the filename associated with the content
// $resultArray[$p] = $content;
}//if file
} //endforeach;
// $resultArray holds your stripped content
// do something with $resultArray;