How To Use Code - PLZ HELP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

m311ton
Forum Newbie
Posts: 7
Joined: Wed Jan 22, 2003 5:45 pm

How To Use Code - PLZ HELP

Post by m311ton »

Alright, for starters I know nothing about PHP besides what I have read here and there around this website.

Recently I downloaded a news posting w/comments code from eveilwalrus.com but I have no clue how to get it to work or what to do with it. Its exactly what Im looking for and desperately need though. I need to be able to have a news headline on a webpage where people can come and comment on it. Please, if anyone would help and let me know what to do so I can get it to work!!
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

emmm...

Post by uberpolak »

Urgh, that's kinda tricky with just that information, how far along have you got? Are you in a position where you have a bunch of code you know nothing about, or are you trying to customize it for your site and you got stuck? Asking someone to fix it all up for you without doing anything yourself is a pretty tall order, but some people might be up for it.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

It might be an idea (if you haven't already) to do some tutorials:
http://www.php.net/tut.php
http://www.phpcomplete.com
http://www.phpbuilder.com
http://www.devshed.com

That way you can ask the right questions and you'll have a better understanding of the answers that you get. It makes it a lot easier for everyone really.

Mac
m311ton
Forum Newbie
Posts: 7
Joined: Wed Jan 22, 2003 5:45 pm

Post by m311ton »

Alright, let me try and explain a problem in a simple code and maybe I can take the solution and apply it to the code I found...

As found on the tutorial, I used the following code...

<form action="action.php" method="POST">
Your name: <input type="text" name="name" />
Your age: <input type="text" name="age" />
<input type="submit">
</form>

and created a action.php with the following code...

Hi <?php echo $_POST["name"]; ?>.
You are <?php echo $_POST["age"]; ?> years old.

However when I fill out the information and click submit, on the following page nothing shows up. When I use a PHP editor, I get an error message that says "undefined index"......what does that mean?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

if your version of php is less that 4.0.6 then you should use $HTTP_POST_VARS as oppsed to $_POST
m311ton
Forum Newbie
Posts: 7
Joined: Wed Jan 22, 2003 5:45 pm

Post by m311ton »

Tried that, but I still get the error message..

Notice: Undefined index: name in action.php on line....
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

in the example you give everything should work. there is probably a problem with the actual code you are using. show us that along with the full error message. that should help.
m311ton
Forum Newbie
Posts: 7
Joined: Wed Jan 22, 2003 5:45 pm

Post by m311ton »

Using the code that I posted before, I get this error message after clicking submit...

"Hi
Notice: Undefined index: name in C:\WINDOWS\Desktop\asdf\action.php on line 9
. You are
Notice: Undefined index: age in C:\WINDOWS\Desktop\asdf\action.php on line 10
years old.
"

Where C:\Windows\Desktop\asdf\ is where the files saved. Thats all there is to it, im confused :?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

that still dosen't help. can you do a complete copy&paste of your code so we can see exactly what is going on?
m311ton
Forum Newbie
Posts: 7
Joined: Wed Jan 22, 2003 5:45 pm

Post by m311ton »

The following code is in index.htm

<html>

<head>
<title></title>
</head>

<body>

<form action="action.php" method="HTTP_POST_VARS">
Your name: <input type="text" name="name" />
Your age: <input type="text" name="age" />
<input type="submit">
</form>


</body>

</html>

And the following is in action.php

<html>

<head>
<title></title>
</head>

<body>

Hi <?php echo $HTTP_POST_VARS ["name"]; ?>.
You are <?php echo $HTTP_POST_VARS ["age"]; ?> years old.


</body>

</html>

Thats the exact code I am using and the error message is as follows

Hi
Notice: Undefined index: name in C:\WINDOWS\Desktop\asdf\action.php on line 9
. You are
Notice: Undefined index: age in C:\WINDOWS\Desktop\asdf\action.php on line 10
years old.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

if that is a direct copy&paste then your problem lies in the fact that you have one space to many in the way you are calling the arrays. instead of:

Code: Select all

$HTTP_POST_VARS &#1111;"name"]
use:

Code: Select all

$HTTP_POST_VARS&#1111;"name"]
that should do it. if not then im stumped.
m311ton
Forum Newbie
Posts: 7
Joined: Wed Jan 22, 2003 5:45 pm

Post by m311ton »

I greatly appreciate you taking the time to help me, but Im sorry to say that it still did not work. I have gone through multiple tutorials and done as you have suggested, but yet nothing seems to work. I guess PHP just isnt the way to go for now, so Ill try something else. Thank you again for your help, if anyone else has this problem/solution let me know.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

im blind. in your form code you have this:

Code: Select all

<form action="action.php" method="HTTP_POST_VARS">
change it to this:

Code: Select all

<form action="action.php" method="post">
there are only two possible values for method, get and post
m311ton
Forum Newbie
Posts: 7
Joined: Wed Jan 22, 2003 5:45 pm

Post by m311ton »

still doesnt work
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

tried seeing if i could duplicate there here on my machine but i couldn't. always worked fine. here is the code im using.

index.html:

Code: Select all

&lt;html&gt;

&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;form action="action.php" method="post"&gt;
Your name: &lt;input type="text" name="name" /&gt;
Your age: &lt;input type="text" name="age" /&gt;
&lt;input type="submit"&gt;
&lt;/form&gt;


&lt;/body&gt;
&lt;/html&gt;
action.php:

Code: Select all

<html>

<head>
<title></title>
</head>

<body>

Hi <?php echo $_POST['name']; ?>.
You are <?php echo $_POST['age']; ?> years old.


</body>

</html>
i am running PHP 4.3.0
Post Reply