Page 1 of 2
From a form to a database?
Posted: Thu Mar 27, 2003 2:53 pm
by AbrasiveRock
Ok, being the major newbie that I am, I may have bitten off more than I can chew. What I want to do is be able to type something into a text box on one page, press the button, and have it go to another page that displays the text in a semi-permanent way.
Here is my attempt:
First page
Code: Select all
<form action="secondpage.php" method="POST">
Enter Your Name:
<input type="text" name="userName">
<input type="submit" name="submit" value="go">
</form>
That then goes to...
Code: Select all
<?php echo $_POSTї"userName"]; ?>
This does not seem to work at all and any help would be appreciated.
Posted: Thu Mar 27, 2003 3:35 pm
by twigletmac
What version of PHP are you using? If you're not sure, use this code to find out:
Mac
Posted: Thu Mar 27, 2003 5:01 pm
by Cogs
Try $HTTP_POST_VARS["userName"];
Posted: Fri Mar 28, 2003 1:38 am
by AbrasiveRock
twigletmac wrote:What version of PHP are you using? If you're not sure, use this code to find out:
Mac
Ok, I tried that as...
as well as...
(
the question mark/close bracket wont show up at the end, but I used it)
and neither told me what version of PHP I am using. Did I have something in the code wrong? Although I'm pretty sure it's the latest one. I think it's PHP 4.3.2RC1, but I could be wrong.
Posted: Fri Mar 28, 2003 2:38 am
by twigletmac
That's weird, the code came from here:
http://www.php.net/manual/en/function.phpversion.php
Is PHP running properly? Do you get anything if you run a file with just:
in it?
Mac
Posted: Fri Mar 28, 2003 3:19 am
by volka
if not open the "source view" in your browser. If you can see the complete text of the script there your server does not parse php at all and you have to check your installation again.
btw: you opened the script via
http://localhost/... or similar?

Posted: Fri Mar 28, 2003 3:14 pm
by AbrasiveRock
That is what is so strange, all the other PHP works fine. Also, View Source only gives me the html like it should, not the PHP. That little script should have worked.
FTR-I should be on AIM and MSN all day Saturday (after 12 noon PST) if anyone is willing. My nic on both is just 'abrasiverock'.
Posted: Sun Mar 30, 2003 5:22 am
by AbrasiveRock
Ok, I know this is going to sound sad and pathetic, but I just got the PHP info thing to work...I think?
http://216.177.247.144/phpinfo.php and it says that "Current PHP version: 4.2.2".
So now I'm going to crash and work all Sunday on trying to learn how to conquer the original task of this post...taking information from a text box and adding it to a database.

Posted: Sun Mar 30, 2003 6:29 am
by volka
if still nothing appears try
Code: Select all
<html><body><pre>
<?php
echo 'POST: ';
print_r($_POST);
echo 'GET: ';
print_r($_GET);
echo 'REQUEST: ';
print_r($_REQUEST);
echo '$HTTP_POST_VARS: ';
print_r($HTTP_POST_VARS);
echo 'HTTP_GET_VARS: ';
print_r($HTTP_GET_VARS);
?>
</pre></body></html>
Posted: Sun Mar 30, 2003 12:22 pm
by AbrasiveRock
Ok, my first page says...
Code: Select all
<html>
<head>
<title>Enter text page</title>
</head>
<BODY BGCOLOR="#303030" TEXT="FFFFFF" LINK="yellow" VLINK="orange" ALINK="red">
<form action="secondpage.php" method="POST">
Enter Your Name:
<input type="text" name="userName">
<input type="submit" name="submit" value="go">
</form>
</body>
</html>
and the second page looks like...
Code: Select all
<html>
<head>
<title>second page</title>
</head>
<body>
<table border=1 BGCOLOR="#303030" width="100%" height="100%">
<TR>
<td width="25%" valign="top"><font color="#FFFFFF"><B>My stuff should post below</b><hr>
#This is the only part I care about right now
#This is just where I want stuff to echo, post, print
<?php echo $_POSTї"userName"]; ?>
<?php print "$userName<BR>";
?>
<?php
$filePointer = fopen("data.txt","w");
fputs($filePointer, "$userName\r\n", 1024);
fclose($filePointer);
?>
</font>
</td><td width="75%" valign="top"><font color="#FFFFFF"><?php echo $_POSTї"NothingRightNow"]; ?></font>
</td></tr><tr height="1%"><td>
<font color="#FFFFFF">Blah Blah Blah!</font>
</td><td>
<form action="secondpage.php" method="POST">
<textarea name="NothingRightNow" COLS="63" ROWS="1"></textarea>
<input type="submit" name="submit" value="GO!">
</form>
</tr>
</TABLE>
</body>
</html>
Posted: Sun Mar 30, 2003 1:40 pm
by twigletmac
Is it still not working? Did you try the code Volka gave you?
Mac
Posted: Sun Mar 30, 2003 1:56 pm
by AbrasiveRock
Well, it shows up on the next page the first run through, but does not write to the database. So the text on the page goes away as soon as someone tries to type something in the text box at the bottom.
Posted: Sun Mar 30, 2003 3:52 pm
by phice
Make sure that your file is CHMODed to 777.
Posted: Sun Mar 30, 2003 3:56 pm
by volka
with
database you refer to
<?php
$filePointer = fopen("data.txt","w");
fputs($filePointer, "$userName\r\n", 1024);
fclose($filePointer);
?>
? If so keep in mind that
fopen(...,"w"); will not set the filepointer to the end of the file; every request will overwrite the previous content.
fputs($filePointer, "$userName\r\n", 1024);
which one did work,
echo $_POST["userName"]; or
print "$userName<BR>" ?
What do you want to achieve?
Posted: Sun Mar 30, 2003 4:14 pm
by AbrasiveRock
So if I understand you correctly, the text put into the text box on the first page, goes to the second page, and then is covered up the the...
Code: Select all
fputs($filePointer, "$userName\r\n", 1024);
...line of code? Should I take it out or change it to make it write to a database? Or did I totally miss what you said?