edit --
I was able to figure this out however I only want to display .png files that are found in my directory. Is there a way to only show png files by adding something to this code?
<?php
$path = 'testimages';
$handle = #opendir('./' . $path . '/');
while ($file = #readdir($handle)){
if("." === $file || ".." === $file) continue;
echo ', {' . "\n" . ' id: ' . preg_replace("#\.[^\.]+$#", "", $file) . ',' . "\n" . 'name: "Product ' . preg_replace("#\.[^\.]+$#", "", $file) . '",' . "\n" . 'imageUrl: "' . $file . '",' . "\n" . 'thumbnailUrl: "' . $file . '",' . "\n" . 'openUrl: "' . preg_replace("#\.[^\.]+$#", "", $file) . '.html"' . "\n" . '}' . "\n";
}
#closedir($handle);
unset($handle,$file,$path);
?>
Related
In php, I want to pass a php variable using the jquery.post method.
The first figure shows the code that post the variable
first
The second figure shows to read the posted variable.second
php variable contains some statements, but output will print the variable names like "$rxss", "$sxss".
The post method seems to be writing the data part incorrectly, so please let me know how to write it.
add
i already tested
echo '<script type="text/javascript">
$(document).ready(function() {
$.post("scanner/getStatus.php", {testId:' . "$testId" . ',chkCnt:' . "$chkCount" . ',rxss:' . "$rxss" . ',sxss:' . "$sxss" . ',sqli:' . "$sqli" . ',basqli:' . "$basqli" . ',autoc:' . "$autoc" . ',idor:' . "$idor" . ',dirlist:' . "$dirlist" . ',bannerdis:' . "$bannerdis" . ',sslcert:' . "$sslcert" . ',unredir:' . "$unredir" . ',clamav:' . "$clamav" . '}, function(data){$("#status").html(data)});
var refreshId = setInterval(function() {
$.post("scanner/getStatus.php", {testId:' . "$testId" . ',chkCnt:' . "$chkCount" . ',rxss:' . "$rxss" . ',sxss:' . "$sxss" . ',sqli:' . "$sqli" . ',basqli:' . "$basqli" . ',autoc:' . "$autoc" . ',idor:' . "$idor" . ',dirlist:' . "$dirlist" . ',bannerdis:' . "$bannerdis" . ',sslcert:' . "$sslcert" . ',unredir:' . "$unredir" . ',clamav:' . "$clamav" . '}, function(data){$("#status").html(data)});
}, 500); ......
-
echo '<script type="text/javascript">
$(document).ready(function() {
$.post("scanner/getStatus.php", {testId:' . "$testId" . ',chkCnt:' . "$chkCount" . ',rxss:"" + $rxss + "",sxss:"" + $sxss + "",sqli:""+ $sqli + "",basqli:"" + $basqli + "",autoc:"" + $autoc + "",idor:"" + $idor + "",dirlist:"" + $dirlist + "",bannerdis:"" + $bannerdis + "",sslcert:"" + $sslcert + "",unredir:"" + $unredir + "",clamav:"" + $clamav + ""}, function(data){$("#status").html(data)});
var refreshId = setInterval(function() {
$.post("scanner/getStatus.php", {testId:' . "$testId" . ',chkCnt:' . "$chkCount" . ',rxss:"" + $rxss + "",sxss:"" + $sxss + "",sqli:""+ $sqli + "",basqli:"" + $basqli + "",autoc:"" + $autoc + "",idor:"" + $idor + "",dirlist:"" + $dirlist + "",bannerdis:"" + $bannerdis + "",sslcert:"" + $sslcert + "",unredir:"" + $unredir + "",clamav:"" + $clamav + ""}, function(data){$("#status").html(data)});
}, 500); ......
but when these test not showing getStatus.php and apache log haven't error
You can you this $("$yourvariable")
Also take a look at this How to call PHP function from string stored in a Variable
I checked out this post but no luck :
PHP - concatenate or directly insert variables in string
The suspect in question: showUser(3, change, " . $name . ");'> $name breaks the code; the second $name does work. The variable does not get passed to the function.
I have been testing for hours to get this to work! It seems like it should work.
I tried checking other places in the application to see what the problem could be and this seems to be the culprit.
<?php
if ($q !== "") {
$q = strtolower($q);
$len=strlen($q);
foreach($a as $name) {
if (stristr($q, substr($name, 0, $len))) {
if ($hint === "") {
$hint = "<p onClick='DoIt(); showUser(3, change, " . $name . ");'>" . $name . "</p>";
} else {
$hint .= "\n" . "$name";
}
}
}
?>
JavaScript probably is requiring $name to be quoted.
$hint = "<p onClick='DoIt(); showUser(3, change, \"" . $name . "\");'>" . $name . "</p>";
Escaping the quotes like this will cause them to appear in the JS function call.
Quotes are often a thorny problem when mixing PHP, JavaScript and HTML on one line.
You can quote your variable like this
if ($q !== "") {
$q = strtolower($q);
$len = strlen($q);
foreach($a as $name) {
if (stristr($q, substr($name, 0, $len))) {
if ($hint === "") {
$name = "'" . $name . "'";
$hint = '<p onClick="DoIt(); showUser(3, change, ' . $name . ');">' . $name . '</p>';
} else {
$hint .= "\n" . "$name";
}
}
}
}
I need to output some strings in the onclick anchor function.I have used proper escaping but anyhow its returning error.
My code is:
$output .= '<a title="Minus this" href="#" onclick = removefromCart("' . $item . '", "' . $nonce . '", ' . $deductQty . ');></a>';
And also used this :
$output .= '<a title="Minus this" href="#" onclick = "removefromCart("' . $item . '", "' . $nonce . '", ' . $deductQty . ')"></a>';
But in both cases there is Uncaught SyntaxError: Unexpected token }
The quotes is totally wrong. Do this way, using the first one:
$output .= '<a title="Minus this" href="#" onclick=\'removefromCart("' . $item . '", "' . $nonce . '", ' . $deductQty . ');\'></a>';
See the 's I have added and removed spaces? And please, next time, don't mingle both PHP and JavaScript. It's confusingly dangerous.
See also:
Are single quotes allowed in HTML?
Is there a better way to write this php code?
You should use single quotations to represent string in HTML element
$output .= '<a title="Minus this" href="#" onclick = "removefromCart(\'' . $item . '\', \'' . $nonce . '\', ' . $deductQty . ')"></a>';
For greater than or equal to PHP5
$output .= '<a title="Minus this" href="#" onclick = removefromCart($item,$nonce,$deductQty);></a>';
For Less than PHP5 try it
$output .= '<a title="Minus this" href="#" onclick = removefromCart(' . $item . ',' . $nonce . ', ' . $deductQty . ');></a>';
I have a php query like so:
<?php
$query = "SELECT * FROM " . $usertable . " ORDER BY fname;";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
echo '<option value="' . $row['pkid'] . '">' . $row['fname'] . ' ' . $row['lname'] . '</option>';
}
?>
Within this same .php file I have some javascript. All I would like to do is return $row['fname'] as a a javascript variable.
Is this possible?
If you want to output the PHP variable in a JavaScript variable you could do something like this -
echo '<script>var name+' . $row['pkid'] . ' = ' .$row['fname'] . ';</script>';
This would give you a uniquely named variable for each row.
To generate the stockroom drop down list
function einv_generateStockrmSelectDropdown($Stockrm,$field,$dropdown) {
//connect to database
base_connectDatabase();
echo "<select id=\"stockrm\" name=\"".$field."[]\" multiple=\"multiple\" style=\"align:left\" class=\"form-control\">";
if (isset($Stockrm) && ($Stockrm != "")) {
$stockrmname = einv_getStockrmDetail($Stockrm);
echo "<option value=\"". $Stockrm ."\">". $stockrmname['einv_stockrm_name'] ."</option>";
} else {
$Stockrm = 0;
}
$getStockrmSQL = base_executeSQL("SELECT * FROM einv_stockroom WHERE einv_stockrm_id<>" . $Stockrm . " ORDER BY einv_stockrm_name");
while ($Stockrmdata_row = base_fetch_array($getStockrmSQL)) {
if (base_num_rows($getStockrmSQL)!= 0) {
echo "<option value=\"".$Stockrmdata_row['einv_stockrm_id']."\">".$Stockrmdata_row['einv_stockrm_name']."</option>";
}
}
echo "</select>";
echo "<script src=\"../terms_base/js/jquery.multiple.select.js\"> </script>";
//Input some codes to split the dropdown and make it into the setSelects. By default, the first time = AutoSelectAll
if(isset($dropdown) && ($dropdown != "")) { //dropdown = 1;2;3
$SDDArrays = explode(";", $dropdown);
$countTrap0 = count($SDDArrays);
$drop = "$('#stockrm').multipleSelect(\"setSelects\", [";
$counting = 1;
foreach ($SDDArrays as &$value) {
if ($countTrap0 != $counting) {
$drop .= "'". $value . "',";
} else {
$drop .= "'". $value . "'";
}
$counting++;
}
$drop .= "]);\n";
} elseif (isset($dropdown)) { //dropdown=
$drop = "$('#stockrm').multipleSelect(\"uncheckAll\")";
} else { //
$drop = "$('#stockrm').multipleSelect(\"checkAll\")";
}
echo "<script>\n";
echo "$(function() {\n";
echo "".$drop."";
echo "});\n";
echo "$(\"#stockrm\").multipleSelect({ onClose: function() {
document.getElementById('search').click();
}});\n";
echo "$(\"#stockrm\").multipleSelect();\n";
echo "</script>";
//close the database
base_closeDatabase();
}
//This function is use to add new stock room
//code = stock room code
//name = stock room name
//desc = stock room description
//remark = stock room remark
//cat = stock room category
add stockroom function
function einv_addStockrm($code,$name,$desc,$remark,$cat)
{
//connect to database
base_connectDatabase();
$User = base_getUserDetail($_SESSION['uID']);
base_executeSQL("INSERT INTO einv_stockroom (einv_stockrm_code, einv_stockrm_name, einv_stockrm_desc, einv_stockrm_remark, einv_stockrm_cat)
VALUES ('" . $code . "', '" . $name . "', '" . $desc . "', '" . $remark . "', '" . $cat . "')");
base_addTransactionLog('Manage Stock Room', 'Add',
"
Stock Room Code = " . $code . " ||
Stock Room Name = " . $name . " ||
Stock Room Description = " . $desc . " ||
Stock Room Remark = " . $remark . " ||
Stock Room Category = " . $cat . "
");
//go to stock room page
echo '<script type="text/javascript">' . "\n";
echo 'window.location="../einventory/stockrm_list.php";';
echo '</script>';
//close the database
base_closeDatabase();
}
Edit stockroom
function einv_editStockrm($srid,$code,$name,$desc,$remark,$cat)
{
//connect to database
base_connectDatabase();
$User = base_getUserDetail($_SESSION['uID']);
$Stockroom = einv_getStockrmDetail($srid);
base_executeSQL("UPDATE einv_stockroom
SET einv_stockrm_code='" . $code . "',
einv_stockrm_name='" . $name . "',
einv_stockrm_desc='" . $desc . "',
einv_stockrm_remark='" . $remark . "',
einv_stockrm_cat = '" . $cat . "'
WHERE einv_stockrm_id=" . $srid . "");
base_addTransactionLog('Manage Stock Room', 'Edit',
"
Stock Room Code = " . $code . " ||
Stock Room Name = " . $name . " ||
Stock Room Description = " . $desc . " ||
Stock Room Remark = " . $remark . " ||
Stock Room Category = " . $cat . "
");
//go to stock room page
echo '<script type="text/javascript">' . "\n";
echo 'window.location="../einventory/view_stockrm.php?id='. $srid .'";';
echo '</script>';
//close the database
base_closeDatabase();
}
File name: add_Stockroom.php and edit_stockroom.php
I have a dropdown list named Stockroom where it displays an array of values.
Example:
Stockroom
[A]
[B]
[C]
When user clicks on [A], it will display relevant data fields that [A] possess (appears below stockroom ddl).
And as user clicks on [B], there is an onchange function that will then show [B] data fields (fields in A is deleted and replaced with B).
I am able to add the initial values however, as i want to edit and change the stockroom from [A] to [B] which will result in a whole new data to be stored, i am unable to do so.
Any ideas?
I believe i have to amend my edit stockroom function where i require a set of coding such as
If the array is selected, i have to delete existing data and add new data in accordance to the selected ID.