I currently have PHP code that fetches some html from the database, it then passes this as JSON to jquery which parses the JSON. Until that moment all is good. However, if you then change some styles in TinyMCE it attaches this as style to the element. (E.g. <h1 style="font-weight:bold">)
Next time the script tries to retrieve this, the JSON doesn't parse, because of the double apostrophes. Is there any way to make TinyMCE not use double apostrophes?
EDIT WITH SOME ACTUAL CODE
PHP Storer:
$conn = mysql_connect($row['ipdb'],$row['usernamedb'], $row['wwdb']) or die("err");
$db = mysql_select_db($row['usernamedb']) or die("err");
$id = $_POST['id'];
$column = $_POST['column'];
$page = $_POST['page'];
$value = $_POST['value'];
$qry = "UPDATE ".$page." SET ".$column."='$value' WHERE id='$id'";
$result = mysql_query($qry) or die("An error occurred ".mysql_error());
PHP Fetcher:
$conn = mysql_connect($row['ipdb'],$row['usernamedb'], $row['wwdb']) or die("err");
$db = mysql_select_db($row['usernamedb']) or die("err");
$identifier = $_POST['identifier'];
$page = $_POST['page'];
$qry = "SELECT id, textnl, texten FROM ".$page." WHERE identifier='$identifier'";
$result = mysql_query($qry) or die("An error occurred ".mysql_error());
$obj = mysql_fetch_object($result);
$textnl = $obj->textnl;
$texten = $obj->texten;
$id = $obj->id;
echo '{ "textnl" : "' . $textnl . '", "texten" : "' . $texten . '", "id" : "' . $id . '" }';
Try to use stripslashes http://www.php.net/manual/es/function.stripslashes.php. Maybe can help you.
Related
I am using following code .
<?php
$dbhost = 'localhost';
$dbuser = '****';
$dbpass = '******';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT * FROM mytable';
mysql_select_db('sujeet_db');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
echo "EMP ID :{$row['firstname']} <br> ".
"EMP NAME : {$row['lastname']} <br> ".
"EMP SALARY : {$row['doj']} <br> ".
"--------------------------------<br>";
}
echo "Fetched data successfully\n";
mysql_close($conn);
?>
to get data from db . But I want to store these data in JavaScript variable for future use. Like var users=$row; but it is not working.
You can do this by putting your mysql result in json format and print it with script tag to use it in javascript like:
<script>
var result = '<?php echo json_encode($row);?>';
</script>
you could do this by assigning inside script tag here is how.
<script>
var spge = '<?php echo json_encode($row); ?>';
alert(spge);
console.log(spge);
</script>
I want to build an array in PHP from SQL query and send it back via ajax to my JS file.
$id = clear(filter_input(INPUT_POST, 'id'));
$sql = 'SELECT * FROM `counties` WHERE `id`="'.$id.'"';
$query = mysqli_query($con, $sql);
$array = array();
while($result = mysqli_fetch_array($query)) {
$id = $result['id'];
$name = $result['name'];
$array[] = array('id' => $id, 'name' => $name);
}
echo json_encode($array);
This is my code. In response I have always just one element. There's a lot of more. How could i do that correctly? I was browsing whole Internet and I didn't find anything useful... :(
$id = $_POST['id'];
$query = mysqli_query($con, "SELECT id,name FROM `counties` WHERE `id`='$id'");
$array = mysqli_fetch_all($query,MYSQLI_ASSOC);
echo json_encode($array);
this may simplified code
I am new to PHP and Highchart. Currently, I am trying to:
1. Query my data from MySQL using PHP.
2. To display HighChart :: Javascript, get data from json_encode in PHP.
Problem now, my PHP is 5.1.6 (I have a few applications running since few years back, try not to upgrade the php). I cannot use the json_numeric_check.
Help Needed :
Question 1: is there any alternative way to get the value without json_numeric_check?
Question 2: Is there any package I can add in to php 5.1.6 to use json_numeric_check?
This is the code I want to use ::
print json_encode($result,json_numeric_check);
My Full Code
<?php
header("Content-Type:application/json");
include_once "shift.php";
list($s1,$e1,$shift) = shift_frame();
$servername = 'localhost';
$username = "";
$password = "";
$select = "SELECT EH_CELLNUM, COUNT(EH_SERIALID)";
$table = " FROM T_EEDATA";
$rule1 = " WHERE (EH_END_DT between ".$s1." and ".$e1.") group by EH_CELLNUM";
$conn = mysql_connect($servername,$username,$password) or die("Connection failed: " . mysqli_connect_error());
mysql_select_db("eedata",$conn) or die(mysql_error());
$sql = $select.$table.$rule1;
$query = mysql_query( $sql, $conn );
$category = array();
$category['name'] = 'Cellnum';
$series1 = array();
$series1['name'] = 'SerialID';
while($row = mysql_fetch_array($query)){
$category['data'][] = $row['EH_CELLNUM'];
$series1['data'][] = $row['COUNT(EH_SERIALID)'];
}
////////////code add here???/////////////////////////////
$result = array();
array_push($result,$category);
$result2 = array();
array_push($result,$series1);
print json_encode($result,json_numeric_check);
mysql_close($conn);
?>
you can do someting to $result before json_encode
for example:
$result = array("1", "2", "3", "4");
$result = array_str_to_int($result);
// only for simple array,you can optimize the code
function array_str_to_int($array){
$tmp_arr = array();
foreach( $array as $k => $v ){
$tmp_arr[] = intval($v);
}
return $tmp_arr;
}
Pulling my hair out with this. Suddenly receiving the following error which wasn't there before:
>>PHP Notice: Undefined index: rmvFileList in C:\wamp\www\somesubdirectory\members\delete.php on line 7
This is coming from an Ajax submission to delete.php. Although the "notice" is appearing, the script is executing properly as it should (database deletion completed correctly, file deleted correctly, and the success call being logged correctly in the console.log). Probably just some sort of sick obsession, but I want to get rid of the warning popping up in my error log every time the delete script is called.
Here is the ajax:
var rmvFile = "Some file name";
$.ajax({
type: "POST",
url: "delete.php",
dataType:"text",
data: {'rmvFileList' : rmvFile },
success: function(returnData) {
console.log(returnData);
}
});
And here is delete.php:
<?php
session_start();
include('../../phpincl/db.php');
$table = 'phoeteo_img_' . $_SESSION['memberID'] . '_' . $_SESSION['showID'];
$name = $_POST['rmvFileList']; <<--This is line 7
$sql = "SELECT * FROM $table WHERE imgNameTime = '$name'";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
while($row = mysqli_fetch_assoc($result))
{
$toBeDeletedIndex = $row['imgIndex'];
$toBeDeletedFilename = $row['imgNameTime'];
$sql = "DELETE FROM $table WHERE imgNameTime = '$name'";
mysqli_query($conn, $sql) or die('Failed: ' . mysqli_error($conn));
$path = 'repository/' . $_SESSION['memberID'] . '_' . $_SESSION['showID'] . '/' . $toBeDeletedFilename;
unlink($path);
}
echo $name;
?>
Any and all help would be greatly appreciated. Thanks!
set isset in php:check code below :
if(isset($_POST['rmvFileList'])){
$name = $_POST['rmvFileList'];
$sql = "SELECT * FROM $table WHERE imgNameTime = '$name'";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
while($row = mysqli_fetch_assoc($result))
{
$toBeDeletedIndex = $row['imgIndex'];
$toBeDeletedFilename = $row['imgNameTime'];
$sql = "DELETE FROM $table WHERE imgNameTime = '$name'";
mysqli_query($conn, $sql) or die('Failed: ' . mysqli_error($conn));
$path = 'repository/' . $_SESSION['memberID'] . '_' . $_SESSION['showID'] . '/' . $toBeDeletedFilename;
unlink($path);
}
echo $name;
}
Any ideas on Exporting HTML5 Form data to CSV please?
I can only use HTML5 or Javascript or both.
Thanks
You could just display the form data in CSV format in the browser (maybe in a popup) and have the user do a File -> Save Page (assuming it doesn't have to be fully automated).
OK, this is what I'm going to have to do: 1. If there IS internet connection ... then save the data to MySQL Table. 2. Using PHP run a script on the MySQL DB to export the data to CSV.
I'll use something like this for example:
<?php
$host = 'localhost';
$user = 'mysqlUser';
$pass = 'myUserPass';
$db = 'myDatabase';
$table = 'products_info';
$file = 'export';
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field']."; ";
$i++;
}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."; ";
}
$csv_output .= "\n";
}
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>