无法使用php从mysql中获取带空格的字段值


Cant get field values with space from mysql using php

我正试图通过href传递包含带空格值的变量,但无法获得带空格的预期输出。

我使用的代码是:

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>";

update.php中,我可以看到链接为

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

我没有得到全名和dob以及的电子邮件

我的变量值如下:

$id=abc
$name=Giridharan Rengarajan
$dob=1993-07-22
$email=rgiridharan.93@gmail.com

我应该怎么做才能获得update.php中的所有四个值?

由于空格不是查询字符串的合法部分,因此必须对它们进行编码。

例如:使用rawurlencode/rawurldecode

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

您可以通过以下方式获取update.php中的变量:

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

为了正确创建url,可以使用http_build_query。请参阅此处的示例http://www.php.net/manual/en/function.http-build-query.php

创建一个params数组,把它像字符串一样放入这个函数和更新脚本中。