So, we just finished the SQL Series last week and for today we’re gonna start on another series in which I’ll share the
problems that I’ve encountered during my projects and it’ll be whether a PHP/HTML/SQL problem.
The first problem that we’ll discuss is passing a variable to another page without the use of a form.
So, it’s considered a php and html problem. In the usual case, to send a variable and its value, we’ll use the html
form. But sometimes there is a need to pass the variable without the use of forms.
Now, there are two ways to do this.
1. The first way is by using a link. We pass through the variable and its value by
using link. Look at the code below.
<a href=”nextpage.php”>CLICK HERE</a> —> Now this is the usual way to create a link to another page.
To pass the variable, we’ll add something to the opening <a> tag.
<a href=”nextpage.php?name=’john'”>CLICK HERE</a>
If you notice, before sending what the variable is and its value, we put ?
and we can put even multiple variables by adding & after the value.
I put ‘____’ for john and yez but there’s no ‘_____’ for 23 because ‘___-‘ is for string characters.
NOW the first part is done. Since this is the send variable part, we’ll need to catch the variable back
in the page we sent it to. So how do we do this?
We use $_GET.
$kkk = $_GET[‘name’]
—> Now the variable $kkk has the value of john.
2. The second way is by using sessions. Once you start a session, the value you put in the $_SESSION[‘___’]
will always be there until it’s destroyed. Look at the code below.
$_SESSION[‘anything’] = 123;
abc = $_SESSION[‘anything’];
So now the variable abc has the value of 123.
It’s that simple, hope you guys could practice doing this and keep on your journey of going deeper into SQL and other languages.