Page 1 of 1

[RESOLVED] using $_POST

Posted: Thu Jan 15, 2009 7:25 am
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

Re: using $_POST

Posted: Thu Jan 15, 2009 7:45 am
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

Re: using $_POST

Posted: Thu Jan 15, 2009 7:54 am
by bubs81
That works great - thank you!!!! :D