[RESOLVED] using $_POST

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

Post Reply
bubs81
Forum Newbie
Posts: 4
Joined: Thu Jan 15, 2009 7:22 am

[RESOLVED] using $_POST

Post by bubs81 »

Hello all,

I've been looking at this code for ages now and can't seem to work out what is wrong. I keep getting the following message "Notice: Undefined index: name1 in C:\Program Files\EasyPHP 3.0\www\formtest.php on line 16"

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form method="post" action="http://localhost/page2.php?img_id=17647.jpg">
Input1: <input type="text" name="name1" id="ins1"><br />
Input2: <input type="text" name="name2" id="ins2"><br />
Input3: <input type="text" name="name3" id="ins3"><br />
<input type="submit" value="submit">
</form>

<?php
$textfieldcontent1 = $_POST['name1'];
?>

</body>
</html>


Can anyone help me figure out why I'm getting this message?

Thanks in advance!

bubs81
Last edited by bubs81 on Thu Jan 15, 2009 7:54 am, edited 1 time in total.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: using $_POST

Post by susrisha »

1. You cannot use the post variable in the same page. It has to be posted from some other page
2. Try using the same code in your page2.php

And here is a solution for the piece of code you wrote

Code: Select all

 
//check if there is a variable "name1" in the post variables and then assign
if(isset($_POST['name1']))
{
$textfield1=$_POST['name1'];
}
//should be able to work
 
 
try it out and tell me if its fixed
bubs81
Forum Newbie
Posts: 4
Joined: Thu Jan 15, 2009 7:22 am

Re: using $_POST

Post by bubs81 »

That works great - thank you!!!! :D
Post Reply