Revos Posted August 31, 2006 Share Posted August 31, 2006 this is my code:[code]<html><body><form method="post"><input name="Pass" type="password" maxlength="10" /><input name="Send" type="submit" value="Ok" /></form><?php $Pass = $_POST["Pass"];if($Pass == "bla"){echo "Successfuly connected!";}else{echo "Wrong password!";}?></body></html>[/code]Now it works fine but when I just open the page is shows me Wrong password!1]What is the problem?2]How can I open a page with php? let's say instead of echo "Successfuly connected!" I want it to open a page called XX.php, how?3]I am not sure this is PHP but I will ask here, I got button called XX how can I make that when I press it the value of text named XY will change to "444"?Thanks and I am sorry to ask so much but I am a newbie at this.. Quote Link to comment Share on other sites More sharing options...
trq Posted August 31, 2006 Share Posted August 31, 2006 1/ You need to check the form has been submitted.[code=php:0]<?phpif (isset($_POST["Pass"])) { $Pass = $_POST["Pass"]; if ($Pass == "bla") { echo "Successfuly connected!"; } else { echo "Wrong password!"; }}?>[/code]2/ Yoy can use the [url=http://php.net/header]header[/url]() function to redirect, or the [url=http://php.net/include]include[/url]() function to include a file.3/ You are correct.... this sounds like a javascript question, not php. Quote Link to comment Share on other sites More sharing options...
Revos Posted August 31, 2006 Author Share Posted August 31, 2006 ok, can you explain more about this line:if (isset($_POST["Pass"])) {(I am not sure but I think isset is checking if it's null..anyways I would love to hear an explanation)And about my two other questions, thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted August 31, 2006 Share Posted August 31, 2006 It checks to see if the variable $_POST['Pass'] is set. This variable will only be set if your form has been submitted, hance the code within that if{} will only run when the form has been submitted. Quote Link to comment Share on other sites More sharing options...
Revos Posted August 31, 2006 Author Share Posted August 31, 2006 What do you mean is set?You mean if it has been submitted then start the if part?ok, I will ask in JS forum, are you sure it's JS and not HTML?by the way, thanks :) Quote Link to comment Share on other sites More sharing options...
trq Posted August 31, 2006 Share Posted August 31, 2006 [quote]What do you mean is set?[/quote]Bassicaly, $_POST['Pass'] does not exists (is NOT set) unless your form is submitted.As for question 3. It could be done in php but sound slike it would be much better suited to a client side tech like javascript. Can you post an example of what you mean? Quote Link to comment Share on other sites More sharing options...
Revos Posted August 31, 2006 Author Share Posted August 31, 2006 I can't find it right now but here I will explain:I made button:<input name="Change" type="button" value="Change" />Now I also made a text box:<input name="ChangedTxt" type="text" />What I am willing to do it when I press the button Change the value of ChangedTxt will be "123"About my second question, I tried this code:header("Location: http://www.phpfreaks.com"); but it gives me an error.. Quote Link to comment Share on other sites More sharing options...
trq Posted August 31, 2006 Share Posted August 31, 2006 Yeah... more suited to javascript. We have a [url=http://www.phpfreaks.com/forums/index.php/board,6.0.html]javascript[/url] forum specifically for such questions.As for your error. I assume its the common [i]headers already sent[/i]? See [url=http://www.phpfreaks.com/forums/index.php/topic,95562.0.html]here[/url]. Quote Link to comment Share on other sites More sharing options...
Revos Posted August 31, 2006 Author Share Posted August 31, 2006 Ok, thank you I asked there.About the headers problem this is exact problem I got:Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Projects\a.php:13) in C:\wamp\www\Projects\a.php on line 26At line 13 I have an HTML code and at line 26 is the code of the header..Is there any other way exept header? Quote Link to comment Share on other sites More sharing options...
trq Posted August 31, 2006 Share Posted August 31, 2006 [quote]At line 13 I have an HTML code and at line 26 is the code of the header..Is there any other way exept header?[/quote]Post your code. Quote Link to comment Share on other sites More sharing options...
Revos Posted August 31, 2006 Author Share Posted August 31, 2006 [code]User name:<input name="User" type="text" /> <br />Password:<input name="Pass" type="password" maxlength="10" /> <br /><input name="Send" type="submit" value="Login =]" /></form><?php if (isset($_POST["Pass"])) { $Pass = $_POST["Pass"]; $User = $_POST["User"]; if($Pass == "bla" and $User == "bla2") { echo "Successfuly connected!<br>"; header("Location: http://www.phpfreaks.com"); }...?>[/code]from line 10 untill line 27. Quote Link to comment Share on other sites More sharing options...
trq Posted August 31, 2006 Share Posted August 31, 2006 Ok... what you need do is wrap your html within the if{} so that it is only displayed when needed. eg;[code=php:0]<?php if (isset($_POST["Pass"])) { $Pass = $_POST["Pass"]; $User = $_POST["User"]; if($Pass == "bla" and $User == "bla2") { header("Location: http://www.phpfreaks.com"); }} else { echo " User name: <input name=\"User\" type=\"text\" /> <br /> Password: <input name=\"Pass\" type=\"password\" maxlength=\"10\" /> <br /> <input name=\"Send\" type=\"submit\" value=\"Login =]\" /> </form>";}?>[/code]Also note that there is no need to try and display the [i]Successfuly connected![/i] as it will not be displayed prior to a redirect and will only cause you grief. Quote Link to comment Share on other sites More sharing options...
Revos Posted August 31, 2006 Author Share Posted August 31, 2006 Thank you very much!oh and if you are making something huge that is a hell of a work... Quote Link to comment Share on other sites More sharing options...
trq Posted August 31, 2006 Share Posted August 31, 2006 [quote]oh and if you are making something huge that is a hell of a work...[/quote]Not sure what you mean exactly... just to let you know though, your html does not need to be embedded within php, thats just my prfered method. This would be just as effective.[code=php:0]<?php if (isset($_POST["Pass"])) { $Pass = $_POST["Pass"]; $User = $_POST["User"]; if($Pass == "bla" and $User == "bla2") { header("Location: http://www.phpfreaks.com"); }} else {?>User name:<input name="User" type="text" /> <br />Password:<input name="Pass" type="password" maxlength="10" /> <br /><input name="Send" type="submit" value="Login =]" /></form>";<?php}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.