...

View Full Version : $_POST['submit'] not getting set



enaceo
05-20-2008, 07:39 PM
Hi there .
I have a problem getting this code to work - it's a login page i'm making for a site - but for some reason it's not wroking .


<?php

require_once("functions.php");
connection("localhost","abcd","&#37;","logintest");

if(isset($_POST['submit'])) {$user=$_POST['user'];
$passw=$_POST['passw'];

if(authorization($user,$passw)) {
echo "<center><h3><b>".$user."<br />Name and password OK . Access approved!</b></h3>
<a href=\"sectionA.php\">Section A</a> | "."<a href=\"sectionB.php\">Section B</a> | ".
"<a href=\"logout.php\">Logout</a></center>";
}
else { echo "<center><hr>".$_POST['user']."<br />NAME OR PASS WRONG ACCESS DENIED!</hr></center>
<center><a href='".$_SERVER['PHP_SELF']."'>Back</a>";
}
}
else {

?>

<center><form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" >
<table>
<tr>
<td>Username</td><td><input type="text" name="user" /></td>
</tr>
<tr>
<td>Password(case sensitive):</td>
<td><input type="password" name="passw" /></td>
</tr>
<tr>
<td><input type="reset" value="Reset values" /></td>
<td><input type="submit" /></td>
</tr>
</table>
</form>
</center>
<?php
}
?>

This is the login page - if the form has not been submitted then it should displaya login form , which it does .When the submit button is pressed , the page should reload and display the links .However , it does not ... it reloads and it displays the form again .After some personal debugging attemps , I foudn out that the problem is the
if(isset($_POST['submit'])) part .If I insert an $aux or something equal to one there the page reloads but like this it does not work ...
Also , here is the code for the functions I used :


<?php
session_start();

header("Cache-control: private");
function connection($host,$user,$passw,$db) {
$conn=mysql_connect($host,$user,$passw) or
die("Cannot establish connection");
mysql_select_db($db,$conn) or die("Cannot access database");
}
function authorization($user,$passw) {
$passw=md5($passw);
$rez=mysql_query("SELECT username,password FROM users WHERE username='$user' AND password='$passw'");
if(mysql_num_rows($rez)==1) {
session_start();
$_SESSION['user']=$user;
$_SESSION['passw']=$passw;
$_SESSION['id']=session_id();
return true;
}
else return false;
}
function authenthification() {
if($_SESSION['id']!=session_id()) {return false;}
else { $rez=mysql_query("SELECT username,password FROM users WHERE username='".$_SESSION['user']."' AND password='".$_SESSION['passw']."'");
if(mysql_num_rows($rez)!=1)
return false;
else
return true;
}
}
?>


I'd be really grateful is somebody could tell me what the problem is ...

I'm using PHP 5.2.5 MySQL server 5 on Apache 2.2 .

kbluhm
05-20-2008, 07:49 PM
Well gee wiz. The button has no name.

You only have:

<input type="submit" />

Inigoesdr
05-20-2008, 07:49 PM
You need to name your form input(s).

<input type="submit" name="submit" value="Submit" />

enaceo
05-20-2008, 07:54 PM
Aaaah...i am really stupid.
Thanks a lot for the help .Now it works .
I was lookin through all my other files that used the same methods (with post) and i looked over the "<form .../>" line probably 100 times but I just didn't see the name was missing :|.
Again , thanks for the pointer ... and a big "Duh!" to me ...

abduraooft
05-20-2008, 07:59 PM
Is there any problem in using the name="submit" for a form element? I remeber a case where I was getting an error form.submit() is not a function, when I called the submit via javascript.

Inigoesdr
05-20-2008, 08:06 PM
Is there any problem in using the name="submit" for a form element? I remeber a case where I was getting an error form.submit() is not a function, when I called the submit via javascript.
If you were using Javascript to submit the form it could be a problem. But this user isn't, and a lot of people probably won't.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum