0

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?

3
  • What your question has to do with mysql? Commented Jul 21, 2013 at 8:10
  • $query_string = 'id='.urlencode($id).'&name='.urlencode($name).'&dob='.urlencode($dob).'&email='.$email; echo htmlentities($query_string); print " <a href=update.php?htmlentities($query_string)>Update Details</a> <br> Student ID: $id<br> Student Name: $name<br> Date Of Birth: $dob<br> Email ID: $email<br>"; <br> the urs i got is localhost/student_portal/… how can i extract values from that.? Commented Jul 21, 2013 at 8:13
  • @srain still i could not able to get the full name. Commented Jul 21, 2013 at 8:40

3 Answers 3

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

it returns only first part of my name (ie before the space)
0

You can get the variables in update.php by:

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.