user2603693
user2603693

Reputation:

Cant get field values with space from mysql using php

I am trying to pass variable that containing the values with space through href but I fail to get the expected output with space.

The code I used is:

print " <a href=update.php?id='$id'&name=$name&dob='$dob'&email='$email'>Update Details</a> <br>
        Student ID: $id<br> Student Name: $name<br> Date Of Birth: $dob<br> Email ID: $email<br>";

In update.php I could see the link as

localhost/student_portal/update.php?id='abc'&name=Giridharan

and I didn't get the full name and dob and email

My variables with values are as follows:

$id=abc
$name=Giridharan Rengarajan
$dob=1993-07-22
[email protected]

What should I do to get all the four values in update.php?

Upvotes: 0

Views: 1072

Answers (3)

Duleendra
Duleendra

Reputation: 497

Since spaces are not legal parts of the query string you have to encode them.

Eg: Use rawurlencode / rawurldecode

<a href=update.php?id='$id'&name=rawurlencode($name)&dob='$dob'&email='rawurlencode($email)'>Update Details</a>

Upvotes: 1

Andrej
Andrej

Reputation: 7504

For proper creation of url you can use http_build_query. See examples here http://www.php.net/manual/en/function.http-build-query.php

Create array of your params, put it into this function and to your update script like a string.

Upvotes: 0

srain
srain

Reputation: 9082

You can get the variables in update.php by:

<?php
$id = $_GET['id'];
$name = $_GET['name'];
$dob = $_GET['dob'];
$email = $_GET['email'];

Upvotes: 0

Related Questions