I have this Code, which is based in a File named trainerModuleView.php and i need the variable lastDeletedUser in a File named database.php
echo '<script>
$.ajax({
url: "trainerModulview.php?groupID="+$currentGroupID+"&lastDeletedUser="+$id,
success: function(data) {
},
});
</script>';
I have a Group with students and if i delete one of them, i would like to have the variable in my URL, so i can $_GET['lastDeletedUser'] it later in the database.php. The problem is though, that the URL doesn't even change.
Pls halp Thanks in advance
You can always just end and start your PHP instead of echoing it. Also you can use <?=$VARIABLE?>
notation to add a variable to any non-php code.
?>
<script>
$.ajax({
url: "trainerModulview.php?groupID="<?=$currentGroupID?>&lastDeletedUser=<?=$currentGroupID?>",
success: function(data) {
},
});
</script>
<?php
Also, Javascript and Jquery notation uses '+' to add a JS variable into a JS string.
var variable=1;
var yourstring="this the #"+variable+" string";
While php uses '.'.
$variable=1;
$yourstring="this the #".$variable." string";
Also, if you are using double quotes, you can just do, but it's better if you still use '.'.
$yourstring="this the #$variable string";
But for single quotes you need to use '.'.
$yourstring='this the the #'.$variable.' string';
Also, you can do this to make more clean instead of echo:
<?php
$phpstring='this is php';
?>
<script>
var jsstring='this is JS';
var phpstring='<?=$phpstring?>';
alert(phpstring);
</script>
<?php
echo $phpstring;
?>
You are using + operator to concat string inside php. You need to USE . "Dot" operatore to cancat strings with variables.
echo '<script>
$.ajax({
url: "trainerModulview.php?groupID="'.$currentGroupID.'"&lastDeletedUser="'.$id.'",
success: function(data) {
},
});
';