473,569 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

newby trying to use GET to return variable to script in same page

I have a simple html form and a bit of PHP in the same page, and I
want the script to get the entry from the form, and write it to a
file. I dont think I'm allowed to use POST on my webspace. Here is my
code ;

<p>&nbsp;
<form method="GET">
Type in a groovy word and press enter<input type="text"
name="groovywor d">
<br>

</form></p>
<?php

// ** file created on 12/03/2005 17:18:03 **
// ** file created by Charlie Fortune
// ** Funk Name Generator

function addname ($word){
if (!file_exists(" Funk name elements.txt")) touch ("Funk name
elements.txt") ;
$fp=fopen("Funk name elements.txt",' a');
fwrite($fp,"$wo rd\r\n");
fclose($fp);
}
if (isset($groovyw ord))
addname($groovy word);
?>

what am I doing wrong ? I can see the entry in the url, but nothing is
being written to the file..
Jul 17 '05 #1
3 1548
On 12 Mar 2005 16:05:11 -0800, go****@charlief ortune.com (charlie fortune)
wrote:
I have a simple html form and a bit of PHP in the same page, and I
want the script to get the entry from the form, and write it to a
file. I dont think I'm allowed to use POST on my webspace.
That would be a cruel and unusual restriction. What makes you think that?
Here is my code ;

<p>&nbsp;
<form method="GET">
Type in a groovy word and press enter<input type="text"
name="groovywo rd">
<br>

</form></p>
You haven't got a submit button, which puts you at the mercy of the browser
deciding to submit when you press enter or similar. Add a submit button.
<?php
// ** file created on 12/03/2005 17:18:03 **
// ** file created by Charlie Fortune
// ** Funk Name Generator

function addname ($word){
if (!file_exists(" Funk name elements.txt")) touch ("Funk name
elements.txt ") ;
$fp=fopen("Funk name elements.txt",' a');
You can remove the 'touch' call if you use mode 'a+' (append if exists, create
if not).

Filenames with spaces cause pain in various situations, consider replacing
spaces with underscores or similar. This isn't required, just a suggestion.
fwrite($fp,"$wo rd\r\n");
It's up to you what line endings you use, but Unix-style plain "\n" is
generally preferred over Windows-style "\r\n".
fclose($fp);
} if (isset($groovyw ord))
addname($groovy word);


There is nothing in this script that will set $groovyword unless you are using
either a very old version of PHP, or a newer version with the register_global s
option set to true, which is strongly recommended to be set to false.

Change these lines to:

if (isset($_GET['groovyword']))
addname($_GET['$groovyword']);

Another issue to consider; what if two people run this script at the exact
same time? You might want to look at http://uk.php.net/flock . Or even move up
a level and use a database; handling concurrent access is one of the several
fundamental reasons to use a proper database.

--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
Thanks for your reply, Andy, it's very helpful. I'm still not quite
there, though.

When I tried to "POST" i got an Error 405 POST method not permitted,
so that's why I thought I would have to use "GET". I am following this
up with my hosts.

My script is now as follows, however I know that it isn't calling the
function, because the .txt file isn't being created.

<p>&nbsp;
<form method="GET">
Type in a groovy word<input type="text" name="groovywor d">
<br>
<input type="submit" value="file it">
</form></p>
<?php

// ** file created on 12/03/2005 17:18:03 **
// ** file created by Charlie Fortune
// ** Funk Name Generator

function addname ($word){
$fp=fopen("Funk _name_elements. txt",'a+');
fwrite($fp,"$wo rd\n");
fclose($fp);
}
if(isset($_GET["groovyword "]))
addname($_GET["groovyword "]);
?>
Originally, I had the php as a separate file on the server, in the
same directory,and called it with <form action="funk_fi ler.php"> and
it worked fine except for the fact that it went to a new blank page
every time it filed an entry. I want it to regenerate the same page
with an empty field. (I would also like to conquer the returning
values to the same page concept). What is the way around this ?

Have I got this right ; a GET or POST method creates an associative
array with the name part of the element as a key ? Even with
register_global s off ?

Also, in your reply, you put

if(isset($_GET['groovyword']))
addname($_GET['$groovyword']);

with a $ in front of groovyword in addname, but I tried with and
without, and I guessed that the way I have it at the top is correct ?

Anyway, I really appreciate your help. I am reading a book too, but
you can't ask books questions....
Jul 17 '05 #3
charlie fortune wrote:
Thanks for your reply, Andy, it's very helpful. I'm still not quite
there, though.

When I tried to "POST" i got an Error 405 POST method not permitted,
so that's why I thought I would have to use "GET". I am following this
up with my hosts.

My script is now as follows, however I know that it isn't calling the
function, because the .txt file isn't being created.


You are doing two things, a GET and a filesystem operation, and you need to
isolate which one is not working. Methinks you have a filesystem problem.
Try this simple sanity check:

<?php
echo "is this what you typed: ".$_GET["groovyword "];
?>

Which should settle once and for all for you that the variable is getting
through to your server.

With that settled, write yourself a little file:

FILE:Testme.php
<?php
$fp=fopen("Test .txt","a+");
$fwrite($fp,"sa nity check");
fclose($fp);
echo "I wrote the file, check now to see if it worked";
?>

And then invoke http://example.com/Testme.php

....which will tell you if you your file commands are working.

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec )ure(Dat)a(.com )
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2179
by: WindAndWaves | last post by:
Hi Gurus I am keen to make a search page on a website, but I have absolutely zero experience with PHP. I am going to hire an expert, but I thought that it may pay to try it a bit first myself (I do want to learn how to do it). What I have is a search page (HTML) and an access database. Now, can someone give me some clues or links on...
2
2311
by: Gill Bates | last post by:
I'm trying to login to a banking site (https://www.providentconnection.com) using vb.net. I've tried many variations of WebClient and HttpWebRequest; none of which I've got to work. My latest version is: Dim myWebClient As New WebClient Dim nvc As New NameValueCollection nvc.Add("Login", username) nvc.Add("Password", password)
41
10645
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET / VB page and I created a variable "query": Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query = String.Format("SELECT * FROM dbo.documents WHERE ") & query End Sub
12
2918
by: Phil Certain | last post by:
Hi, I'm trying to do something very simple...or at least it should be. I have created a host page (gen.aspx) and a very simple user control (us.ascx). The corresponding code-behind files are gen.aspx.vb and uc.ascx.vb. With simple html or self contained vb in the user control, everything is fine and dandy. So the next stage is to pass back...
10
1459
by: John Baker | last post by:
Hi: This is the only ASP newsgroup I can access using Verizon, and I would like to know a real basic piece of information. I am totall new to ASP, although I have done HTML coding. Say I The following code is intended to ask for an individuals HIRE Number and then pass it on to a query, which returns time data for the week. It doesn't...
18
2246
by: Ed Jay | last post by:
<disclaimer>js newbie</disclaimer> My page has a form comprised of several radio buttons. I want to poll the buttons to determine which button was selected and convert its value to a string. I then want to use the string on the same page. My script is: function checkRadio(field) { for(var i=0; i < field.length; i++) {
20
6941
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt = document.getElementById('hometab'); Has anyone ever seen anything like this before, or am I dreaming?
11
16908
by: Rob | last post by:
I know, I know, don't use frames. Well, I'm stuck with these frames and I'm trying to add functionality without a complete redsign. You can look at this as a nostalgic journey. Anyway, I've got the following frame structure at the top level: FRAMESET CODE <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">...
1
3131
by: rsteph | last post by:
I've got some product information pages, with images and text, all setup within a table. I'm trying to add a small image in the upper right hand corner of the content div (where all the important information is). I've got the product name at the top, left aligned and typically as a two lined header, and I'd like to add a small logo to the right of...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.