Jump to content

server removes 2nd word in word_blank_word string


jaco

Recommended Posts

Hello everyone, I am having a problem with a pagination script to be used to display table results.

 

The script for the Next button reads like this:

echo '<a href=http://www.lightmypump.com/pumpdatabase2/return-pump-pagination.php?s='. ($start + $display) . '&cp=' . ($current_page+1) . '&p_type=' . $searchpumptype .'><b><big>Next </big></b></a>>';</big></b></a>>';

 

this basically is a link to the same page with some variables sent to the server and recalled using:

 

if (isset($_GET['p_type']))

$searchpumptype = $_GET['p_type'];

else

$searchpumptype = $_GET['searchpumptype'];

 

the problem is some of these variables are 2 words separated by a blank space such as "centrifugal horiz."

 

The var. that is returned by the server  for p_type is "centrifugal" it omits the second word and this screws things up.

 

I am now thinking of very complicated ways to eliminate the blank space and then add it back later.

 

But maybe there is a simple solution?

 

CHeers,

Link to comment
Share on other sites

you can replace spaces with underscores than when y ou get the var, replace underscores with spaces again

echo '<a href=http://www.lightmypump.com/pumpdatabase2/return-pump-pagination.php?s='. ($start + $display) . '&cp=' . ($current_page+1) . '&p_type=' . str_replace(" ", "_", $searchpumptype) .'><b><big>Next </big></b></a>>';</big></b></a>>';

Link to comment
Share on other sites

Yes, that's an option. Thank you.

I suppose I could also use the explode function which gets rid of the blank and creates an array and then the implode function which reverses it.

 

Why does the server not see the word_blank_word combination as a complete string?

 

Cheers,

Link to comment
Share on other sites

Right you are Matthew. Here is a shortened version of the code that shows the behavior. The dropdown has two selections: a single word and a two word string with a blank space. If you select the single word and press the Display button you get it back as is. If you press the Next link you also get the word back as is. If you select the double word and press Next you get back the first part of the word only.

 

Code:

<?php
// standard html web header
require 'header.html';
// html user data input form
echo "<form action =". $_SERVER['PHP_SELF']." method = \"GET\">"; 

if (isset($_GET['p_type']))
	 $searchpumptype = $_GET['p_type'];
	 else		 
	 $searchpumptype = $_GET['searchpumptype'];
echo  "<br />";
echo "searchpumptype is: ".$searchpumptype;

echo  "<br />";
echo "<b>Pump type</a>: ";

echo "<select name=\"searchpumptype\">";

if ($searchpumptype == "bellows") echo  "<option SELECTED value=\"bellows\">bellows</option>";
else echo	"<option value=\"bellows\">bellows</option>";
if ($searchpumptype == "centrifugal horiz") echo	"<option SELECTED value=\"centrifugal horiz\">centrifugal horiz</option>";
else echo	"<option value=\"centrifugal horiz\">centrifugal horiz</option>";

echo  "<br />";
echo "<input type=\"submit\" value=\"Display\" title =\"Hit this button whenever you change any of the above\">";
echo "</form>";

echo '<a href=test.php?p_type=' . $searchpumptype .'><b><big>Next </big></b></a>>';
// standard html web page footer
require 'footer.html';
?>

 

You can run the script on my web site here:

http://www.lightmypump.com/pumpdatabase2/test.php

Cheers,

 

J

Link to comment
Share on other sites

There is no mistery here. I have not readall the code, but there are two things you need to do:

 

1. Enclose HTML tag parameters in quotes.

 

Wrong:

echo '<a href=' . $value . '>Link</a>

If the $value has a space in it the result will be

<a href=some value.htm>Link</a>

 

Right:

echo "<a href=\"{$value}\"'>Link</a>

 

Also, for any vlaue being put into a URL string you should use urlencode to convert any problematic characters for URL parsing:

 

$value = urlencode($value);
echo "<a href=\"{$value}\"'>Link</a>

 

 

Link to comment
Share on other sites

Thank you very much, seems the problem was with the use of the singlw quote.

 

The following mods. work:

echo "<a href=\"test.php?p_type=$searchpumptype\">"."<b><big>Next </big></b></a>>";

 

this works:

echo "<a href=\"test.php?p_type={$searchpumptype}\">"."<b><big>Next </big></b></a>>";

 

and this works:

$value = urlencode($searchpumptype);
echo "<a href=\"test.php?p_type={$value}\">"."<b><big>Next </big></b></a>>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.