[SOLVED] Post or Get method not being recieved

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
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

[SOLVED] Post or Get method not being recieved

Post by ianhull »

Hi Guys,

I am having another little issue here with get or post.

I have created a form like this

Code: Select all

<form name="form1" id="form1" method="post" action="admin">
                <div align="right">
	<input name="usrname" type="text" id="usrname" />
                <input name="pwd" type="password" id="pwd" />
	<input name="Submit" type="submit" class="style4" value="Submit" />
                 </div>
                </form>
But when I type my username and password I get undefined in my php processor which uses this sql


Code: Select all

$sql = "SELECT companyname, firstname, lastname, email, password, ulevel, username, jobtitle, website FROM users WHERE username='$_POST[usrname]' AND password='$_POST[pwd]' ORDER BY companyname";
I have tried switching to get but it still does not work.
Yet if I type in my browser http://svr1/myadminpage.php?usrname=myu ... mypassword it works great.

Can anyone tell me where my problem is?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post the actual error, and form please.
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

Notice: Undefined index: usrname in C:\Xeneo\vr\admin\index.php on line 4

Notice: Undefined index: pwd in C:\Xeneo\vr\admin\index.php on line 4

Code: Select all

<?php 
include ("connect.php"); 

$sql = "SELECT companyname, firstname, lastname, email, password, ulevel, username, jobtitle, website FROM users WHERE username='$_POST[usrname]' AND password='$_POST[pwd]' ORDER BY companyname"; 

$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print include_once("failedlogin.php");
exit();
}
else{

}
echo "\n";

while ($line = mysql_fetch_array($r))    
      {
      extract($line);
      }
echo "\n";
$usrlevel = "$ulevel";
$adminlevel = "Yes"; 
{ 
  if ($usrlevel == $adminlevel){ 
      echo include("admincontent.php"); 
  } else { 
      echo include("usercontent.php"); 
  } 
}  
?>

Code: Select all

<form name="form1" id="form1" method="post" action="admin">
                  <div align="right">
				    <input name="usrname" type="text" id="usrname" />
				    <input name="pwd" type="password" id="pwd" />
				    <input name="Submit" type="submit" class="style4" value="Submit" />
                  </div>
                </form>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it kind of feels like you're hitting a redirection with the submission, which is tossing the data... can you confirm that?
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

Thanks for you help.

It was because in my html form I was using just the admin folder to redirect to and not the page inside it.

it works great now.

Thanks.

Code: Select all

<form name="form1" id="form1" method="post" action="admin/index.php"> // this line
                  <div align="right"> 
                <input name="usrname" type="text" id="usrname" /> 
                <input name="pwd" type="password" id="pwd" /> 
                <input name="Submit" type="submit" class="style4" value="Submit" /> 
                  </div> 
                </form>
Post Reply