I working on a small form using PHP, the user enter a code a code and if the code is not found the form need to go back, I am trying to do that using this code but it not working
the $code contains the id of the page which is 208, but for some reason is not only printing 208 it is printing %20208 any ideas why is doing this.
<?php
die('<center>code dont exist<br>Try again!</center>
<script type="text/javascript">
function backToMain() {
window.location = "codes.php?id= '.$code. '";
}
setTimeout("backToMain()", 3000);
</script>');
You put a space between id= and the beginning of the $code. The %20 is a space, once the URL is correctly encoded. Remove it:
<?php
die('<center>code dont exist<br>Try again!</center>
<script type="text/javascript">
function backToMain() {
window.location = "codes.php?id='.$code.'";
}
setTimeout("backToMain()", 3000);
</script>');
If your $code can contains space, you should also apply the trim() function on it.
trim will remove all spaces. also remove space after id=.
try this:
<?php
die('<center>code dont exist<br>Try again!</center>
<script type="text/javascript">
function backToMain() {
window.location = "codes.php?id='.trim($code). '";
}
setTimeout("backToMain()", 3000);
</script>');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With