SSam
SSam

Reputation: 1

How to capture values from url?

I am collecting customer data on one page and then taking them to the next page where they select the services that they want. I wish to pass customer name and customer ref no to the next page when they are selecting the services.

I pass the value like this http://www.mywebsite.com/services.php?name={$cust_name}&ref={$ref_no}

What will be the PHP code to capture them in the services.php page

Upvotes: 0

Views: 244

Answers (5)

Shamshad Zaheer
Shamshad Zaheer

Reputation: 247

You can simply get values from URL using $_GET global array.

i.e

$name = $_GET['name'];
$ref = $_GET['ref'];

Upvotes: 1

user1915746
user1915746

Reputation: 587

You can access the URL paremeters with $_GET.

$name = $_GET['name']; 
$ref = $_GET['ref'];

See http://php.net/manual/de/reserved.variables.get.php

Be careful using data like customer name in URL parameters. Somebody could just enter another customer's name and maybe see data which he/she should not be allowed to.

Upvotes: 0

Bilal Ahmed
Bilal Ahmed

Reputation: 4066

if you have this type of link

http://www.mywebsite.com/services.php?name=anyName&ref=1234

then you can get variable like this

$name=$_GET['name'];
$ref=$_GET['ref'];

Upvotes: 0

Xzhibit
Xzhibit

Reputation: 81

On services.php, just use $_GET["name"] and $_GET["ref"] to refer to these variables.

Upvotes: 0

Anis Alibegić
Anis Alibegić

Reputation: 3230

URL to visit:

http://www.mywebsite.com/services.php?name=john&ref=1

Code in services.php:

$cust_name = $_GET["name"]; //john
$ref_no= $_GET["ref"]; //1

Upvotes: 0

Related Questions