esoteric Posted August 14, 2011 Share Posted August 14, 2011 Hi, i have written the script below but im trying to get to check a few things, one is if a variable i enter into the form (which is a password) exists and if not post an error message, if it does exist but i wrong, echo the password is wrong and if it does exist and is right then continue with the rest. For some reason at the moment it doesn't matter i type in a password or not, when hitting submit it just display the error message and the success message together <? $error = ""; $pass = ($_POST['pass']); if(!$pass) { $error .= "Please enter your password! "; } if($error){ echo "<div align='center'><h2>Error!</h2></div>"; echo "<div align='center'>\n<p>$error</p></div>"; echo "<div align='center'>\n</div>"; echo "<div align='center'>\n<p><a href='$HTTP_REFERER'>Return and try again</a></p></div>"; } if (!$error && $pass == 'test'); { $fn = "../../scripts/tabs_index/pages/news.html"; $content = stripslashes($_POST['content']); $fp = fopen($fn,"w") or die ("Error opening file in write mode!"); fputs($fp,$content); fclose($fp) or die ("Error closing file!"); echo "<div align='center'><h2>Change Successful!</h2></div>"; echo "<div align='center'>\n <p>News has been successfully changed and is now live!</p></div>"; echo "<div align='center'>\n---------------------------------------------------------------</div>"; echo "<meta http-equiv=\"refresh\" content=\"3; url=http://xxxxxxxxxxx/account=administrator\" />\n"; } ?> Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/244767-script-problem/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 14, 2011 Share Posted August 14, 2011 use else. <? $error = ""; $pass = ($_POST['pass']); if(!$pass) { $error .= "Please enter your password! "; } if($error){ echo "<div align='center'><h2>Error!</h2></div>"; echo "<div align='center'>\n<p>$error</p></div>"; echo "<div align='center'>\n</div>"; echo "<div align='center'>\n<p><a href='$HTTP_REFERER'>Return and try again</a></p></div>"; } else { if (!$error && $pass == 'test'); { $fn = "../../scripts/tabs_index/pages/news.html"; $content = stripslashes($_POST['content']); $fp = fopen($fn,"w") or die ("Error opening file in write mode!"); fputs($fp,$content); fclose($fp) or die ("Error closing file!"); echo "<div align='center'><h2>Change Successful!</h2></div>"; echo "<div align='center'>\n <p>News has been successfully changed and is now live!</p></div>"; echo "<div align='center'>\n---------------------------------------------------------------</div>"; echo "<meta http-equiv=\"refresh\" content=\"3; url=http://xxxxxxxxxxx/account=administrator\" />\n"; } } ?> use that code. i've edited it for you. Quote Link to comment https://forums.phpfreaks.com/topic/244767-script-problem/#findComment-1257214 Share on other sites More sharing options...
esoteric Posted August 14, 2011 Author Share Posted August 14, 2011 Ops, thanks for the help. It doesn't seem to be checking the password is right though, i can type anything in and it still continues with the script, also how would i go about writing an error message if the wrong pass is entered? thank you. Quote Link to comment https://forums.phpfreaks.com/topic/244767-script-problem/#findComment-1257220 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 14, 2011 Share Posted August 14, 2011 add another else. <? $error = ""; $pass = ($_POST['pass']); if(!$pass) { $error .= "Please enter your password! "; } if($error){ echo "<div align='center'><h2>Error!</h2><>"; echo "<div align='center'>\n<p>$error</p><>"; echo "<div align='center'>\n<>"; echo "<div align='center'>\n<p><a href='$HTTP_REFERER'>Return and try again</a></p><>"; } else { if (!$error && $pass == 'test'); { $fn = "../../scripts/tabs_index/pages/news.html"; $content = stripslashes($_POST['content']); $fp = fopen($fn,"w") or die ("Error opening file in write mode!"); fputs($fp,$content); fclose($fp) or die ("Error closing file!"); echo "<div align='center'><h2>Change Successful!</h2><>"; echo "<div align='center'>\n <p>News has been successfully changed and is now live!</p><>"; echo "<div align='center'>\n---------------------------------------------------------------<>"; echo "<meta http-equiv=\"refresh\" content=\"3; url=http://xxxxxxxxxxx/account=administrator\" />\n"; } else { $error .= "Wrong Password!"; echo "<div align='center'><h2>Error!</h2><>"; echo "<div align='center'>\n<p>$error</p><>"; echo "<div align='center'>\n<>"; echo "<div align='center'>\n<p><a href='$HTTP_REFERER'>Return and try again</a></p><>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/244767-script-problem/#findComment-1257228 Share on other sites More sharing options...
esoteric Posted August 14, 2011 Author Share Posted August 14, 2011 that gave me a syntax error, i tried a different way of writing it (and more simple) <? $error = ""; $pass = ($_POST['pass']); if (!isset($pass)){ echo "Please enter your password!"; } if ($pass != "test") { echo "Wrong Password"; } else { if ($pass == "test"); { $fn = "../../scripts/tabs_index/pages/news.html"; $content = stripslashes($_POST['content']); $fp = fopen($fn,"w") or die ("Error opening file in write mode!"); fputs($fp,$content); fclose($fp) or die ("Error closing file!"); echo "<div align='center'><h2>Change Successful!</h2></div>"; echo "<div align='center'>\n <p>News has been successfully changed and is now live!</p></div>"; echo "<div align='center'>\n---------------------------------------------------------------</div>"; echo "<meta http-equiv=\"refresh\" content=\"3; url=http://http://xxxxxxxx/account=administrator\" />\n"; } } ?> Which seems to be working. Thank you for you help. Quote Link to comment https://forums.phpfreaks.com/topic/244767-script-problem/#findComment-1257236 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 14, 2011 Share Posted August 14, 2011 ok, sorry. please mark topic as solved Quote Link to comment https://forums.phpfreaks.com/topic/244767-script-problem/#findComment-1257240 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.