Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

post form

Status
Not open for further replies.

KryptoS

Programmer
Feb 7, 2001
240
BE
Hey,

filename = first.php

$link = mysql_connect("localhost", "root", "")
mysql_select_db("slim")

<form method=&quot;POST&quot; action=&quot;first.php&quot;>
<input type=&quot;text&quot; name=&quot;name&quot; size=&quot;20&quot;>
<input type=&quot;submit&quot; value=&quot;save&quot; name=&quot;save&quot;>
</form>

After I submitted the form I want to check the data in the form but in the same file (first.php) So I did:

if ($_POST[&quot;name&quot;] = &quot;name&quot;)
echo &quot;correct&quot;;

This works if I submit the form. But the first time (when I load the page) I get the following error:

Notice: Undefined index: name in ...

So I think $_POST can only be used if I submit the page, so is there a way to check the value in a form without the $_POST function? The One And Only KryptoS
 
no. php is server side so you MUST submit the details in some fashion to be able to check the data on the server

also

php uses double equal signs for comparison (==) not single equal signs which are assignments (=)

if ($_POST[&quot;name&quot;]== &quot;somename&quot;)
echo &quot;correct&quot;;

also note that $_POST and $_GET work only with newer versions of php and what the errors says is that php is reading the $_POST[&quot;name&quot;] as an array...check version of php and may need to change to $HTTP_POST_VARS['name']

hth
Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 

The following is a sample version of what I think your trying to do. BUT be warned about refreshing the same page, as this page relies on posted information, so the browser will repost the information. The best way to achieve a simple POST, ACTION, RESPONSE is to create an intermediate page with no displayable content to handle the POST and a redirect back to the original page.

anyname.php
<?php

if(isset($_GET['result']))
{
// this checks if the page URL contains a variable &quot;result&quot; which means it has come back from a dealing with the POST.
if($_GET['result']==&quot;okay&quot;)
{
echo &quot;correct&quot;;
}
else
{
echo &quot;wrong&quot;;
}

}
else
{
?>

<form name=&quot;name_checker&quot; method=&quot;POST&quot; action=&quot;checkit.php
&quot; >
<input type=&quot;hidden&quot; name=&quot;source&quot; value=&quot;<?php echo $_SERVER['PHP_SELF']; ?>&quot; />
<input type=&quot;text&quot; name=&quot;name&quot; size=&quot;20&quot; />
<input type=&quot;submit&quot; value=&quot;save&quot; name=&quot;save&quot; />
</form>

<?php
}
?>

----------------------

checkit.php
<?php

$link = mysql_connect(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;)
mysql_select_db(&quot;slim&quot;)

check database here for valid result
if(checks out okay)
{
$answer=&quot;okay;
}
else
{
$answer=&quot;bad&quot;;
}

header(&quot;location: &quot;.$_POST['source'].&quot;?result=&quot;.$answer);
?>



So when you return to the same page again you either go to page.php?result=okay OR
page.php?result=bad
and a refresh doesn't reprocess the post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top