Skip to content Skip to sidebar Skip to footer

Send A Variable From One Page To Another In Php

I am trying to send a variable value from one page to another. I have used include('form-eidtable.php') in user-edit.php at bottom of the page, Look at the image below: I dont kn

Solution 1:

You could use a a session

$_SESSION['uid'] = $uid;

Read more about sessions here.

http://www.w3schools.com/php/php_sessions.asp

Solution 2:

No need of Javascript. In your form-editable.php, just start a session and copy the desired variable into $_SESSION[] variable.

session_start();
$_SESSION['uid'] = $uid;

And then use it in user-edit.php. Note that here also you will have to start a session.

session_start();
$uid = $_SESSION['uid'];

More on PHP sessions.

Solution 3:

You can use $_GET like that, but you have a syntax error in your Javascript after the PHP runs. You are closing out the string in your redirecturl and then having PHP echo $uid;. This results in Javascript of useredit="344 If you either wrap the PHP block inside the quote or add a + between the JS and the PHP (so long as your $uid is numeric`) it should work without using sessions.

Solution 4:

You can use sessions or cookies the main advantage of the cookie is the fact that the cookie will remain even after the client will close his browser. I won't recommend to use a variable in a GET method and use it without proper validation. This will make your site vulnerable to sql injection attacks. If you want to access it from javascript you can use window.location. But as a rule of thumb please validate your GET variables before using them in your sql queries.

Post a Comment for "Send A Variable From One Page To Another In Php"