pcw Posted March 3, 2011 Share Posted March 3, 2011 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 https://forums.phpfreaks.com/topic/229515-script-will-not-pass-whole-variable-name/ Share on other sites More sharing options...
cunoodle2 Posted March 3, 2011 Share Posted March 3, 2011 Look into URLencode.. http://php.net/manual/en/function.urlencode.php Link to comment https://forums.phpfreaks.com/topic/229515-script-will-not-pass-whole-variable-name/#findComment-1182501 Share on other sites More sharing options...
pcw Posted March 3, 2011 Author Share Posted March 3, 2011 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? Link to comment https://forums.phpfreaks.com/topic/229515-script-will-not-pass-whole-variable-name/#findComment-1182518 Share on other sites More sharing options...
php_ppt Posted March 3, 2011 Share Posted March 3, 2011 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 https://forums.phpfreaks.com/topic/229515-script-will-not-pass-whole-variable-name/#findComment-1182525 Share on other sites More sharing options...
pcw Posted March 3, 2011 Author Share Posted March 3, 2011 yes it does, I am going to give that a go Many Thanks Link to comment https://forums.phpfreaks.com/topic/229515-script-will-not-pass-whole-variable-name/#findComment-1182531 Share on other sites More sharing options...
pcw Posted March 4, 2011 Author Share Posted March 4, 2011 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 https://forums.phpfreaks.com/topic/229515-script-will-not-pass-whole-variable-name/#findComment-1182905 Share on other sites More sharing options...
kenrbnsn Posted March 4, 2011 Share Posted March 4, 2011 Please show us the code you're using to generate the link. Ken Link to comment https://forums.phpfreaks.com/topic/229515-script-will-not-pass-whole-variable-name/#findComment-1182918 Share on other sites More sharing options...
pcw Posted March 4, 2011 Author Share Posted March 4, 2011 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 https://forums.phpfreaks.com/topic/229515-script-will-not-pass-whole-variable-name/#findComment-1182920 Share on other sites More sharing options...
kenrbnsn Posted March 4, 2011 Share Posted March 4, 2011 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 https://forums.phpfreaks.com/topic/229515-script-will-not-pass-whole-variable-name/#findComment-1182929 Share on other sites More sharing options...
Pikachu2000 Posted March 4, 2011 Share Posted March 4, 2011 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 https://forums.phpfreaks.com/topic/229515-script-will-not-pass-whole-variable-name/#findComment-1182930 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.