Jump to content

[SOLVED] Using GET


grungefreak

Recommended Posts

Hi guys,

 

I want to get familiar with using the GET method on my php pages. I want to just get one working and figure the logic from there.

 

Can somebody just give me a piece of code that will do the following:

 

I have foo.php and bar.php files. I want to set a variable in foo.php and grab it in bar.php using $_GET['var']. Then echo it to the screen.

 

I realise this is fairly simple but I always work with $_POST and wanna try $_GET.

 

Thanks in advance.

 

GF

Link to comment
https://forums.phpfreaks.com/topic/99600-solved-using-get/
Share on other sites

This is how it works:

 

<?php
// foo.php
echo "<a href='bar.php?num1=5&num2=3'>bar.php</a>";

// bar.php
if(isset($_GET['num1']) && isset($_GET['num2'])){
    $num1 = $_GET['num1'];
    $num2 = $_GET['num2'];
    $total = $num1 + $num2;
    echo "$num1 + $num2 = $total";
}
?>

 

Excellent!

 

Thank you so much.

 

GF

Link to comment
https://forums.phpfreaks.com/topic/99600-solved-using-get/#findComment-510233
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.