php - Undefined variable on POST -
i looked trough pages , fixed undefined index on username , password undefined variable. had more code decided simplify sake of testing , echo see if changes , doesn't.
<?php if (isset($_post['submit'])){ $uname = isset($_post['username']); $pass = isset($_post['password']); } echo $uname; echo $password; ?>
i this:
notice: undefined variable: uname in c:\xampp\htdocs\8\login.php on line 7
notice: undefined variable: pass in c:\xampp\htdocs\8\login.php on line 8
i not understand what's wrong here. if needed here form page html.
<form id="login" method="post" action="login.php"> <div id="loginon"> <label for="username" style="color:#0f0; font-family:arial, helvetica, sans-serif;" >username: </label> <input type="text" id="username" name="username" /> <br /> <br /> <label for="password" style="color:#0f0; size:auto; font-family:arial, helvetica, sans-serif;">password: </label> <input type="password" id="password" name="password" /> <br /> <br /> <input type="image" src="http://www.clker.com/cliparts/2/g/4/v/k/e/submit-hi.png" border="0" width="180px" height="80px" alt="submit" /> </div> </form> </body>
edit: further problem connected think allowed post here.
if($username == "pikachu" || "cloud") { $ucheck = "dobar"; } else { $ucheck = "los"; } if ($password == "123123" || "132132") { $pcheck = "topar"; } else { $pcheck = "losh"; } if($ucheck == "dobar" && $pcheck == "topar") { echo "najjaci si!"; } elseif ($ucheck == "dobar" && $pcheck == "losh") { echo "wimp."; } elseif ($ucheck == "los" && $pcheck == "topar") { echo "fish."; }
the problem echoes out "najjaci si" no matter type in previous form. ideas?
since have variable decleration inside logic (if), there chance variables not set @ all. try this
<?php if (isset($_post['submit'])){ $uname = isset($_post['username']); $pass = isset($_post['password']); echo $uname; echo $pass; } else { echo "no submit detected!"; } ?>
it doesen't if have actual element named submit. try adding this:
<input type="submit" name="submit" value="send form" />
now, form contains element named "submit" send post parameter when form submitted.
i myself, in need of framework, doing this:
$username = ( isset($_post["username"]) && $_post["username"] != "" ? $_post["username"] : false ); $password = ( isset($_post["password"]) && $_post["password"] != "" ? $_post["password"] : false ); if( !$username === false && !$password === false ) { echo $username . " <br /> " . $password; } else { echo "no! :) "; }
Comments
Post a Comment