0

I am trying to fetch some values from db.Out of these values one column having string values with space(for ex: Amazon vc) and trying to pass that record as query string (by using href link).Here $list_name contains value as Amazon India

$nestedData[]= "<a href=$site_url/vcm/open_addvendorcode_popup.php?id3=$row[client_id]&id4
=$row[list_name]&id5=$row[auto_list_id]&id6=$row[id] id='1' data-toggle='modal' 
data-target='#add_vendorcode_popup$row[edit_id]>Add VC</a>";

When I click on the above link, I can see in url with incomplete List name as Amazon and after list_name,&id5=$row[auto_list_id]&id6=$row[id] this part got missed. I am dispalying this data by using datatable. And when I see by using Inspect Element &list_name=Amazon" India="", but this should display like &list_name="Amazon India". I can not change the data in DB, because it was already inserted. So how can I fix this issue? Any help would be greatly appreciated.

Shadow
  • 33,525
  • 10
  • 51
  • 64
user3408779
  • 981
  • 2
  • 19
  • 43
  • 5
    https://www.php.net/manual/en/function.urlencode.php – AbraCadaver Aug 09 '19 at 17:51
  • Here thie issue is data got missed while displaying when we mouse over on href link. – user3408779 Aug 09 '19 at 17:52
  • 2
    Because it is not encoded properly for a URL. And you want to quote the URL `href='$site_url/vcm/open_addvendorcode_popup.php?id3=$row[client_id]&id4 =$row[list_name]&id5=$row[auto_list_id]&id6=$row[id]'` – AbraCadaver Aug 09 '19 at 17:52
  • Possible duplicate of [MySQL Updates only first name instead of full name](https://stackoverflow.com/questions/56901569/mysql-updates-only-first-name-instead-of-full-name) – user3783243 Aug 09 '19 at 17:56
  • ^The issue on that dup is not related to Mysql. It relates to the browser and spaces as this question does. – user3783243 Aug 09 '19 at 17:57
  • Yes, but when I add urlencode function `&list_name='".urlencode($row[list_name])."'` it is opening directly on browser instead of displaying bootstrap modal popup – user3408779 Aug 09 '19 at 17:57

1 Answers1

1

Okay I'm going to expand on @AbraCadaver's comment:

Explanation:

First what you need to do is store the url into a variable like this:

$url = "{$site_url}/vcm/open_addvendorcode_popup.php?id3={$row[client_id]}&id4={$row[list_name]}&id5={$row[auto_list_id]}&id6={$row[id]}"

Then you want to encode the url using urlencode:

$url_encoded = urlencode($url);

Then you want to use the encoded url within the href attribute of the HTML element:

<a href="<?php echo $url_encoded; ?>" id='1' data-toggle='modal' data-target="<?php echo '#add_vendorcode_popup' . $row[edit_id]; ?>" >Add VC</a>

Shorthand:

Optionally, you can make this shorter like so:

<a href="<?php echo urlencode({$site_url}/vcm/open_addvendorcode_popup.php?id3={$row[client_id]}&id4={$row[list_name]}&id5={$row[auto_list_id]}&id6={$row[id]}); ?>" id='1' data-toggle='modal' data-target="<?php echo '#add_vendorcode_popup' . $row[edit_id]; ?>" >Add VC</a>
adamoffat
  • 639
  • 6
  • 22
  • 1
    `Urlencode($row['list_name']);` is working .you mentioned `url_endode()`.. please check. Any way after changing to `Urlencode()`,it is working. Thank you – user3408779 Aug 09 '19 at 18:24