foreach() triggers 'Uncaught RangeError: Maximum call stack size exceeded' [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm in trouble with a simple php foreach wich attribute classes (odd / even) to divs. I think i have a synthax error because it works but the loop is not ended (Uncaught RangeError: Maximum call stack size exceeded in console :
<?php
$count = 0;
foreach( $this->boutiques_details as $key => $value){
if ($value->ville == $this->ville) {
echo '<div data-lng="$this->escape($value->longitude)" data-lat=" $this->escape($value->latitude)" class="' . (++$count%2 ? "shop odd" : "shop even") . '">';
?>
<p><b><?php echo $this->escape($value->ville)?></b></p>
<p><?php echo $this->escape($value->quartier)?></p>
<p><?php echo $this->escape($value->adresse)?></p>
<p><?php echo $this->escape($value->num_contact_1)?></p>
</div>
<?php
}
}
?>
Thanks for help!

You have some PHP code in the string you're trying to echo, but it's not being evaluated by PHP because it's inside the string:
echo '<div data-lng="$this->escape($value->longitude)" data-lat="$this->escape($value->latitude)" class="' . (++$count%2 ? "shop odd" : "shop even") . '">';
Replace the above with the following:
echo '<div data-lng="' . $this->escape($value->longitude) . '" data-lat="' . $this->escape($value->latitude) . '" class="' . (++$count%2 ? "shop odd" : "shop even") . '">';
This way, the PHP parts (such as $this->escape($value->longitude)) will be recognized by PHP, and their results will be inserted in the string you are echoing.
Because you were echoing the PHP parts directly, javascript (jQuery) probably recognized the dollar sign ($), tried to do something with it but didn't know how, and failed.

Related

Redirect page after press OK using sweetalert [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I've tried to redirect but it's not working. Can anyone help me, please?
if(isset($_POST['submit'])){
if(send_report($_POST['id_truck'], $_GET['id'])){
echo '<script type="text/javascript">';
echo 'setTimeout(function () { swal("Success!","data successfully added","success");';
echo '}, 200); window.location.href = 'report.php' </script>';
} else {
echo '<script type="text/javascript">';
echo 'setTimeout(function () { swal("failed!","Something wrong","warning");';
echo '}, 200), ;</script>';
}
}
You are using single quotes in a string wrapped in single quotes, escape them:
echo '}, 200); window.location.href = \'report.php\' </script>';
Edit:
Now as your page is redirecting, your sweetalert will work but you may not be able to see it.
swal() returns Promise which will be resolved when you click on OK button of sweetalert and thus we will have to wait for it to redirect the page thereafter:
echo '<script type="text/javascript">';
echo 'setTimeout(function () {';
echo 'swal("Success!","data successfully added","success").then( function(val) {';
echo 'if (val == true) window.location.href = \'report.php\';';
echo '});';
echo '}, 200); </script>';

Syntax error while passing the values [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to pass the value one form to another. I am getting ") missing" but I am not getting where I am going wrong. Is this the correct way to call all the parameters?
Uncaught SyntaxError: missing ) after argument list
$("#div1").load("http://ppp.gkdsjfgk.com/wp-content/themes/thestory/compare-form-site.php?loanamt=" +
<?php echo $_POST['loanAmt']; ?>."&occupation=" +
<?php echo $_POST['occupation']; ?>."&rateType=" +
<?php echo $_POST['rateType']; ?>."&age=" +
<?php echo $_POST['age']; ?>."&city=" +
<?php echo $_POST['city']; ?> );
You're using the wrong concatenator just after each of your PHP brackets ?>. The dot (the concatenator for PHP) should be replaced with + (the JavaScript concatenator) like this ?> +.
$("#div1").load(
"http://ppp.gkdsjfgk.com/wp-content/themes/thestory/compare-form-site.php?loanamt=" +
<?php echo $_POST['loanAmt']; ?> + "&occupation=" +
<?php echo $_POST['occupation']; ?> + "&rateType=" +
<?php echo $_POST['rateType']; ?> + "&age=" +
<?php echo $_POST['age']; ?> + "&city=" +
<?php echo $_POST['city']; ?>
);
you are mixing PHP and JavaScript concatenation. (.) is used in PHP and (+) is used in JavaScript
concatenation in PHP is like this:
$val = 'Your'.' '.'val';
concatenation in JavaScript is like this:
var val = 'Your'+' '+'val';
so your code should be like this:
$("#div1").load("http://ppp.gkdsjfgk.com/wp-content/themes/thestory/compare-form-site.php?loanamt="+<?php echo $_POST['loanAmt'];?>+"&occupation="+<?php echo $_POST['occupation']; ?>+"&rateType="+<?php echo $_POST['rateType']; ?>+"&age="+<?php echo $_POST['age']; ?>+"&city="+<?php echo $_POST['city']; ?> );
try this one, first make a variable so that it will be easier to modify if there's still wrong, just comment here what's the error after you try this code.
<script>
// set variable
var loadAmt = "<?php echo isset($_POST['loanAmt']) ? $_POST['loanAmt'] : ''; ?>";
var occupation = "<?php echo isset($_POST['occupation']) ? $_POST['occupation'] : ''; ?>";
var rateType = "<?php echo isset($_POST['rateType']) ? $_POST['rateType'] : ''; ?>";
var age = "<?php echo isset($_POST['age']) ? $_POST['age'] : ''; ?>";
var city = "<?php echo isset($_POST['city']) ? $_POST['city'] : ''; ?>";
// your load variable
var loadVar = "http://ppp.gkdsjfgk.com/wp-content/themes/thestory/compare-form-site.php?loanamt="+loadAmt+"&occupation="+occupation+"&rateType="+rateType+"&age="+age+"&city="+city;
// load to specified div
$('#div1').load(loadVar);
</script>

Get var from a PHP page [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm having a problem with my PHP. I would like to send data from my page to another page. But it's all in PHP. I need to take an input value and a combobox value. And I don't know how to do it.
Here's my PHP :
<?php
session_start();
$q = intval($_GET['q']);
$db = mysql_connect('localhost', 'root', 'root');
mysql_select_db('Projet',$db);
$sql2 = "select IDControle, NomControle from Controle WHERE IDUser='".$_SESSION['id']."'";
$req2 = mysql_query($sql2) or die('Erreur SQL !<br>'.$sql2.'<br>'.mysql_error());
echo'<select id="controleChoix" name="controleChoix">';
while ($data2 = mysql_fetch_array($req2)){
echo '<option value="'.$data2['IDControle'].'">'.$data2['NomControle'].'</option>';
}
echo '</select>';
echo '<input type="hidden" name="selected_text" id="selected_text" value="" />';
$sql = "select ID, Nom, Prenom from User where Groupe ='".$q."'";
$req = mysql_query($sql) or die('Erreur SQL 2!<br>'.$sql.'<br>'.mysql_error());
echo '<ul class="list-group">';
while ($data = mysql_fetch_array($req)){
echo '<li class="list-group-item"><strong>Nom</strong> : '.$data['Nom'].' <br> <strong>Prénom</strong> : '.$data['Prenom'].'<br>';
echo '<input type="text" name="note" id="note"/> ';
echo '<a class="label label-success" href="ajouterNote.php?var1='.$data2['IDControle'].'&var2='.$data['ID'].'&var3='.$test.'"><i class="fa fa-fw fa-check"></i></a></li>';
}
echo '</ul>';
echo '<a class="btn btn-primary" href="#">Ajouter toutes les notes</i></a></li>';
?>
I need to send the input note.value, the select controleChoix.value and the intval q that I've received from another page.
As you already seem to use SESSIONS, you could easily transfer your data from one page to another using these $_SESSION variables.
https://secure.php.net/manual/en/book.session.php
edit: Please keep in mind that this isn't secure at all. The values can easily be changed by the user. Using this you might want to validate the values first, before using.

Javascript not working on a php while cycle [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am trying to execute this javascript code on each database table record.
I have try to define all the div id on the script, but since i am not good a javascript i can not find where is the problem.
I think that javascript should be specified with a uniq name... heres the code:
echo '<script>';
echo '$(document).ready(function(){';
echo 'var menu = $("#shfaqa'.$row["id"].'")';
echo '$("#butoni'.$row["id"].'").click(function(event){';
echo 'event.preventDefault();';
echo 'event.stopPropagation();';
echo 'if (menu.is(":visible"))';
echo '{';
echo 'menu.slideUp(400);';
echo 'jwplayer( "my-video'.$row["id"].'" ).stop();';
echo '}';
echo 'else';
echo '{';
echo 'menu.slideDown(400);';
echo '}';
echo '});';
echo '$(document).not("#shfaqa'.$row["id"].', #butoni'.$row["id"].'").click(function(event) {';
echo 'event.preventDefault();';
echo 'if (menu.is(":visible"))';
echo '{';
echo 'menu.slideUp(400);';
echo 'jwplayer( "my-video'.$row["id"].'" ).stop();';
echo '}';
echo '});';
echo '})';
echo '</script>';
I think you're missing a ; at line 3. This should be better:
echo 'var menu = $("#shfaqa'.$row["id"].'");';
And you're missing a semicolon at the very end as well:
echo '});';
echo '});';
echo '</script>';
But this whole concept has some issues as Implant said
And you could write this whole thing by just using one single echo. Much clearer, isn't it?
echo "<script>
$(document).ready(function(){
var menu = $(\"#shfaqa{$row["id"]}\");
$(\"#butoni{$row["id"]}\").click(function(event){
event.preventDefault();
event.stopPropagation();
if (menu.is(\":visible\"))
{
menu.slideUp(400);
jwplayer( \"my-video{$row["id"]}\" ).stop();
}
else
{
menu.slideDown(400);
}
});
$(document).not(\"#shfaqa{$row["id"]}, #butoni{$row["id"]}\").click(function(event) {
event.preventDefault();
if (menu.is(\":visible\"))
{
menu.slideUp(400);
jwplayer( \"my-video{$row["id"]}\" ).stop();
}
});
});
</script>";
You could set the full javascript in a regular HTML format and echo only the PHP values you need like :
<?php
// any PHP condition here
if($something) {
?>
<script>
var something = <?php echo $row["id"]; ?>;
// more javascript here
</script>
<?php
}; // close php if
?>

Issue with passing data from one html to another [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a variable $var with some value in it in index.php file and i want to access this variable in sample.php after i navigate to sample.php through link. How can i do this with js.
$var
link
Just try this:
index.php
<?php $var= "Great";
?>
link
In sample.php
<?php
if (isset($_GET["data"])){
echo $_GET['data'];
}
?>
index.php
$var = urlencode($var);//in case that the var contains special characters like " ? &
link
sample.php
$var = $_GET['var'];
OR
index.php
$_SESSION['var']=$var;
sample.php
$var = $_SESSION['var'];
since it's all PHP, meaning on the server side, you are better off putting this in the session as indicated in the second example by Exlord.
If you actually need to use it on the client side, then set it in a session cookie:
example from:
http://www.w3schools.com/php/php_cookies.asp
<?php
$cookie_name = "user";
$cookie_value = "Alex Porter";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
?>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_name];
}
?>
</body>
</html>
and retrieve the cookie in javascript:
http://www.w3schools.com/js/js_cookies.asp
var x = document.cookie;
If you'd like to use jquery try the following taking into account you have included the jquery library and have a button to submit the form. This $var can come from a input box. It's not necessary to have a passing the query string.
$("button").click(function(){
var paramVal = '<?php echo $var; ?>';
$.post("sample.php",
{
varparam:paramVal
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
To retrieve the value you will call the following code in the sample.php:
$varParam = $_POST["varparam"];

Categories

Resources