Jump to content

Script problem


esoteric

Recommended Posts

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  :confused:

 

<? 
$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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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><>";
}
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.