spenceddd Posted March 8, 2010 Share Posted March 8, 2010 Hi, I cannot work out how to append my php variable ($username) onto the following code: if (($_POST['username'] == $usernameCheck) && ($_POST['password'] == $passwordCheck)){ session_start(); session_register('username'); //load simpleForm.php page using javascript echo ("<script> <!-- location.replace(\"DevelopmentFiles/JobAdmin/JobAdmin.php\"); --> </script>"); $failureMessage=""; } I am just trying to pass a username to the next page using the url (the location replace bit) so I can retrieve using a get command on the target page. Struggling really to get the exact syntax right... Sorry I am still a php novice! Thanks for any help on this. Spencer Link to comment https://forums.phpfreaks.com/topic/194519-quickie-appending-a-php-variable-into-some-javascript/ Share on other sites More sharing options...
cags Posted March 8, 2010 Share Posted March 8, 2010 if (($_POST['username'] == $usernameCheck) && ($_POST['password'] == $passwordCheck)){ session_start(); session_register('username'); //load simpleForm.php page using javascript echo ("<script> <!-- location.replace(\"DevelopmentFiles/JobAdmin/JobAdmin.php?username={$_POST['username']}\"); --> </script>"); $failureMessage=""; } Not entirely sure why your using JavaScript to redirect, but something like that should work. Link to comment https://forums.phpfreaks.com/topic/194519-quickie-appending-a-php-variable-into-some-javascript/#findComment-1023180 Share on other sites More sharing options...
spenceddd Posted March 9, 2010 Author Share Posted March 9, 2010 Thanks a lot for that cags. The reason by the way is simply because I haven't got a clue what I'm doing (well not much anyway!). Whenever I try to use the headers thing it always errors. Spencer Link to comment https://forums.phpfreaks.com/topic/194519-quickie-appending-a-php-variable-into-some-javascript/#findComment-1023465 Share on other sites More sharing options...
trq Posted March 9, 2010 Share Posted March 9, 2010 Thanks a lot for that cags. The reason by the way is simply because I haven't got a clue what I'm doing (well not much anyway!). Whenever I try to use the headers thing it always errors. Spencer That would likely be because you are sending output before redirecting. The idea sounds silly... why would you send data to the client if all you are going to do is redirect them? All you need do is organise your code so that it only sends data to the client when it is needed. Link to comment https://forums.phpfreaks.com/topic/194519-quickie-appending-a-php-variable-into-some-javascript/#findComment-1023471 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.