muskan
06-05-2009, 12:27 PM
its the code of adding text in website. but when i leave a box blank then it display an error on next. i want that it display error on same page against text boxes.
here is the code
<?php include("C:\\Program Files\\VertrigoServ\\www\\portal\\password_protect .php"); ?>
<html> <title>hotnews</title>
<body background=new2.jpg>
<?php
include("config.php");
if(isset($_POST['submit']))
{//begin of if($submit).
// Set global variables to easier names
$title = mysql_escape_string($_POST['title']);
$text1 = mysql_escape_string($_POST['text1']);
$text2 = mysql_escape_string($_POST['text2']);
//check if (title) field is empty then print error message.
if(!$title){ //this means If the title is really empty.
echo "Error: News title is a required field. Please fill it.";
exit(); //exit the script and don't do anything else.
}
if(!$text1){ //this means If the title is really empty.
echo "Error: News text1 is a required field. Please fill it.";
exit();
}
if(!$text2){ //this means If the title is really empty.
echo "Error: News text2 is a required field. Please fill it.";
exit();
}// end of if
if ((bool) preg_match('/[0-9]/', $title)) {
echo "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br><b>Sorry! Please add only text data !<br>You'll be redirected to ADD Latest News Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=ALN.php>";
exit();
}
if ((bool) preg_match('/[0-9]/', $text1)) {
echo "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br><b>Sorry! Please add only text data !<br>You'll be redirected to ADD Latest News Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=ALN.php>";
exit();
}
if ((bool) preg_match('/[0-9]/', $text2)) {
echo "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br><b>Sorry! Please add only text data !<br>You'll be redirected to ADD Latest News Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=ALN.php>";
exit();
}
//run the query which adds the data gathered from the form into the database
$result = mysql_query("INSERT INTO news (title, dtime, text1, text2)
VALUES ('$title',NOW(),'$text1','$text2')",$connect);
//print success message.
echo "<b>Thank you! News added Successfully!<br>You'll be redirected to Home Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=ALN.php>";
}//end of if($submit).
// If the form has not been submitted, display it!
else
{//begin of else
?>
<br>
<h3>::Add News</h3>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Title: <input name="title" size="40" maxlength="255">
<br>
Text1: <textarea name="text1" rows="7"cols="30"></textarea>
<br>
Text2: <textarea name="text2" rows="7" cols="30"></textarea>
<br>
<input type="submit" name="submit" value="Add News">
</form>
<?php
}//end of else
?>
</body>
</html>
i need urgent help please
here is the code
<?php include("C:\\Program Files\\VertrigoServ\\www\\portal\\password_protect .php"); ?>
<html> <title>hotnews</title>
<body background=new2.jpg>
<?php
include("config.php");
if(isset($_POST['submit']))
{//begin of if($submit).
// Set global variables to easier names
$title = mysql_escape_string($_POST['title']);
$text1 = mysql_escape_string($_POST['text1']);
$text2 = mysql_escape_string($_POST['text2']);
//check if (title) field is empty then print error message.
if(!$title){ //this means If the title is really empty.
echo "Error: News title is a required field. Please fill it.";
exit(); //exit the script and don't do anything else.
}
if(!$text1){ //this means If the title is really empty.
echo "Error: News text1 is a required field. Please fill it.";
exit();
}
if(!$text2){ //this means If the title is really empty.
echo "Error: News text2 is a required field. Please fill it.";
exit();
}// end of if
if ((bool) preg_match('/[0-9]/', $title)) {
echo "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br><b>Sorry! Please add only text data !<br>You'll be redirected to ADD Latest News Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=ALN.php>";
exit();
}
if ((bool) preg_match('/[0-9]/', $text1)) {
echo "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br><b>Sorry! Please add only text data !<br>You'll be redirected to ADD Latest News Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=ALN.php>";
exit();
}
if ((bool) preg_match('/[0-9]/', $text2)) {
echo "Error: News title must not contain numbers. Please refill it, with all numbers removed.<br><b>Sorry! Please add only text data !<br>You'll be redirected to ADD Latest News Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=ALN.php>";
exit();
}
//run the query which adds the data gathered from the form into the database
$result = mysql_query("INSERT INTO news (title, dtime, text1, text2)
VALUES ('$title',NOW(),'$text1','$text2')",$connect);
//print success message.
echo "<b>Thank you! News added Successfully!<br>You'll be redirected to Home Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=ALN.php>";
}//end of if($submit).
// If the form has not been submitted, display it!
else
{//begin of else
?>
<br>
<h3>::Add News</h3>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Title: <input name="title" size="40" maxlength="255">
<br>
Text1: <textarea name="text1" rows="7"cols="30"></textarea>
<br>
Text2: <textarea name="text2" rows="7" cols="30"></textarea>
<br>
<input type="submit" name="submit" value="Add News">
</form>
<?php
}//end of else
?>
</body>
</html>
i need urgent help please