954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help on Simple PHP Form

First name:

Last name:

vbjenny
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

try action="<?php echo $_SERVER['PHP_SELF']; ?>"

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

First name:

email:

vbjenny
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

umm.. I hope you have started apache service and you are executing your script like, http://localhost/yourfilename.php ? When are you getting that error ? After you submit the page ? What is your url ?
PS. Next time you post your code, please wrap it within [ code=php] [ /code] tags.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

no, I found this code on the internet and thought I would try to get it to work before I moved to the next step. I will go get a book. can you recommend one? I have a url, but it is in the very beginning stages

vbjenny
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

No. What I am asking you is, how do you execute your script ? Are you double clicking the file or are you typing the path in the address bar ?
Well, If you want to learn the basics of php, w3schools is the best site to start off.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

I double click on the file from the website and fill in the boxes and submit.

All I really want to end up with at this point is a form the user inputs a name, email and maybe a comment. on submit the data will end up in the mySQL database. The web hosting supports PHP and mySQL. I've done some SQL programming so that will be easier for me to figure out. I also have a CIS degree, but I don't have any experience with web sites at all (other than surfing the net).

Once I get the above code to work, my next step was to add the code for mysql_connect, etc

thanks, jenny

vbjenny
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

hmm. Try this script. Tellme if it works.

<?php
if(isset($_POST['submit'])){
  print_r($_POST);
}
?>
<html>
<body>
<form method="post" action="test.php">
<input type="text" name="name">
<input type="text" name="email">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>


Call this test.php, put it on your server. Tellme if it works.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

it actually liked that code

I'm now getting error messages

Parse error: syntax error, unexpected '{' in /home/n9m4teaw/public_html/test.php on line 2


So what does this mean? should I be using a .php for my code?

vbjenny
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

Yep. You should have an extension .php for your scripts if you want apache to parse php. Can you show us the script you are using ? (because the code example that I gave you shouldn't give this error!)

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 
vbjenny
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

sorry, i forgot the

vbjenny
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

ok, I used the tags

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<?phpif(isset($_POST['submit'])){  print_r($_POST);}?><html><body><form method="post" action="test.php"><input type="text" name="name"><input type="text" name="email"><input type="submit" name="submit" value="submit"></form></body></html><?php
if(isset($_POST['submit'])){
  print_r($_POST);
}
?>
<html>
<body>
<form method="post" action="test.php">
<input type="text" name="name">
<input type="text" name="email">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
vbjenny
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 
<?php
if(isset($_POST['submit'])){
  print_r($_POST);
}
?>
<html>
<body>
<form method="post" action="test.php">
<input type="text" name="name">
<input type="text" name="email">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>


Click on "toggle plain text" and then copy the code. :) And I meant [ code=php] [ /code] ! < without the whitespace.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

Array ( [name] => jenny [email] => vbjenny@msn.com [submit] => submit )

Thank you very much.

You are awesome!!!!!!!!!!!!!

vbjenny
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

Great. That should get you started. Remember, the file extension should be .php for apache to parse it as a php file. And w3schools will help you learn the basics in no time. You can also refer to php.net.
Its 8 am and I should get some sleep now.. Lol..

Cheers,
Naveen

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

I just noticed you are from India. It wasn't until you mentioned what time it was that I looked. very cool. I'm from Hermosa Beach, California USA

vbjenny
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 
nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

I just added my first record to the database!!!!!!!!!!!!!!!!1 :)

You were such a big help yesterday and the W3Schools is a very good website. Thank you for recommending it.

I used 2 pages. the first a .htm page for the form and the 2nd a .php to post to the database.


:) :) :) :) :) :) :) :) :) :) :) :) :) :)

vbjenny
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

:) Good !

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You