Jump to content

Script will not pass whole variable name


pcw

Recommended Posts

Hi, I have this script, it all works fine apart from when I pass the variable on, it only passes the first word and not the whole variable

 

The form that actions to the samples page passes the $siteName as My Test Site, if I type echo $siteName in the sameples page, it will print My Test Site, however when I use this

 

createSample&siteName=$siteName

 

to pass the variable to the next page, it just echos 'My' instead of My Test Site. Even when I scroll over the link above it just shows My in the url.

 

case "samples":

// Get submitted data and assign to variables

$siteName = $_POST['siteName'];
$adminEmail = $_POST['adminEmail'];
$sendmailLoc = $_POST['sendmailLoc'];
$imgdir = $_POST['imgdir'];
$imgdirbase = $_POST['imgdirbase'];

// Write variable data to text file

$FileName = "data/server.txt";
$FileHandle = fopen($FileName, 'w') or die("can't open file");
$data = "<?php\n\$siteName = '$siteName';\n?>";
fwrite($FileHandle, $data);
$data = "<?php\n\$adminEmail = '$adminEmail';\n?>";
fwrite($FileHandle, $data);
$data = "<?php\n\$sendmailLoc = '$sendmailLoc';\n?>";
fwrite($FileHandle, $data);
$data = "<?php\n\$imgdir = '$imgdir';\n?>";
fwrite($FileHandle, $data);
$data = "<?php\n\$imgdirbase = '$imgdirbase';\n?>";
fwrite($FileHandle, $data);
fclose($FileHandle);

// Displays the create sample pages page

ECHO <<<SAMPLES

<table border=0 align=center bgcolor=#00CCFF>
  <tr>
    <td><span class=style1><b><center>Create Sample Pages</center></b></span></td>
  </tr>
  <tr>
    <td>Would you like Member Site Maker to create sample pages for:
<ul>
<li>index.html</li>
<li>login.html</li>
<li>search.html</li>
<li>register.html</li>
</ul>
</td>
</tr>
<tr>
<td><a href=installation.php?cmd=createSample&siteName=$siteName>Yes</a>
</td>
<td><a href=installation.php?cmd=mysql>No</a>

</td>
</tr>

</table>

SAMPLES;

break;

 

Can anybody tell me where I am going wrong please?

 

Thanks

Link to comment
Share on other sites

Hi, thanks for your reply, but I cant see how that will help solve the problem. Could you point me to the relevant part please?

 

URLs have to be encoded....for your example "My Test Site" given the space should be "My%20Test%20Site" (or close approximation)

 

the previous poster pointed to docs on the PHP URL encoder: http://php.net/manual/en/function.urlencode.php

I have never used it but it certainly sounds like what you are looking for.

 

make sense?

 

 

Link to comment
Share on other sites

Ok guys I really am having trouble with this. I have added this into my code with the aim for the variable value to appear in the link with the %20 in between the variable value words.

 

ie My%20Test%20Site

 

But I just cant get it to work.

 

Here is what I have added:

 

The variable $siteName is set to My Test Site

 

function encode_variable(&$siteName)
{
    $siteName = urlencode($siteName);
    $siteName = str_replace("%20", '', $siteName);
    return $siteName;
} 

 

The variable should appear in the link as

 

installation.php?cmd=createSample&siteName=My%20Test%20Site

 

instead it appears as

 

installation.php?cmd=createSample&siteName=My

 

I have read the web page that I was pointed to earlier in this post and experimented with some of the things on there, but I really am having no luck.

Link to comment
Share on other sites

Hi Ken,

 

This is the code

 

// Displays the create sample pages page

ECHO <<<SAMPLES

<table border=0 align=center bgcolor=#00CCFF>
  <tr>
    <td><span class=style1><b><center>Create Sample Pages</center></b></span></td>
  </tr>
  <tr>
    <td>Would you like Member Site Maker to create sample pages for:
<ul>
<li>index.html</li>
<li>login.html</li>
<li>search.html</li>
<li>register.html</li>
</ul>
</td>
</tr>
<tr>

<td><a href=installation.php?cmd=createSample&siteName=$siteName>Yes</a>
</td>
<td><a href=installation.php?cmd=mysql>No</a>

</td>
</tr>

</table>

SAMPLES;

 

Now I have added

 

encode_variable($siteName);
echo $siteName;

 

To the code I displayed in my previous post and in the link and the echo I get My+Test+Site how do I get it so this is %20 instead of + ?

 

I thought this line

 

$siteName = str_replace("%20", '', $siteName);

 

Would take care of that but it doesnt

Link to comment
Share on other sites

The href attribute must be quoted. If you do a show source, you will see the whole name in the source, but the href attribute will end with the first space

<td><a href='installation.php?cmd=createSample&siteName=$siteName'>Yes</a>

 

Ken

Link to comment
Share on other sites

Your href= attributes need to be quoted as unquoted strings in the attribute are not valid html markup. You should then use urlencode() on the url string.

 

echo "<a href=\"" . urlencode("installation.php?cmd=createSample&siteName=$siteName") . "\">Yes</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.