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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undefined variable: Submit in c:\Inetpub\wwwroot\ICA\login 1

Status
Not open for further replies.

NICKYSUWANDI

Programmer
Jan 8, 2004
80
ID
please help!

i am newbie,i don't understand why this error happen.
This sample of my code.
When i preview in browser this error message appear
"PHP Notice: Undefined variable: Submit in c:\Inetpub\ on line 2 "
Someone please help me. Thanks

<?
if( $Submit){
session_start();
session_register("StrUserid");
header("location: index1.php");
}
?>
<form name="form1" method="post" action="login1.php">
<table width="200" border="0">
<tr>
<td width="84">Userid</td>
<td colspan="2"><input name="Struserid" type="text" id="Struserid" size="30"></td>
</tr>
<tr>
<td>Password</td>
<td colspan="2"><input name="StrPass" type="text" id="StrPass" size="30"></td>
</tr>
<tr>
<td colspan="3"><div align="center">
<input type="submit" name="Submit" value="Login">
</div></td>
</tr>
</table>
</form>
 
This means that the variable $Submit has not been defined.

change:
Code:
if( $Submit){
to:
Code:
if(isset($_POST['Submit'])){

If your php ini file has registered globals set to off (which it should be, for security reasons) then you need to use the $_POST, and $_GET arrays for submitted values.

Hope this helps,
Itshim
 
Thanks Itshim, but i got second problem
from index1.php ( header("location: index1.php"); ).
I am learning session, my code return error

"You Are not Login PHP Notice: Undefined variable: struserid in c:\Inetpub\ on line 3 "

This of my code in index1.php

<?php
session_start();
if ($struserid){
echo "Your Name: $struserid";
}else{
echo "You Are Not Login";
}
?>
 
I suppose your problem is still the same and it is register globals. You assume your variables are readily available in the script which was true in older versions of PHP but was since discovered to be a major security hole. Today, you need to reference the variables in their respective arrays, $_GET for the ones transmitted via url, $_POST for posted through form and $_SESSION for those inside a session. Try:
Code:
<?php
session_start();
if ($_SESSION['struserid']) {
   echo "Your Name: " . $_SESSION[struserid'];
} else {   
   echo "You Are Not Login";
}
?>
 
I would suggest you set registered globals to off, if possible.

The error you get means that the variable has not been declared. To check if a variable has been declared use the isset() function such as:
Code:
if (isset($struserid))
If you are expecting the variable to have been declared then there is another problem somewhere in your script.

Hope this Helps.
Itshim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top