Jump to content

edit news error


crystalnano

Recommended Posts

i have a edit news code but i cannot edit code it says

Parse error: syntax error, unexpected '{', expecting '(' in N:\news\prev2~.php on line 57

 

here is code

 

<title>Edit News</title>

<?php

//LAST UPDATE
// 27-09-2007

include("config.php");

$error =  "";
$error1 = "";
$error2 = "";
$error3 = "";
$error4 = "";
$error5 = "";

   $newsid = $_GET['newsid'];


   if(isset($_POST['submit']))
  {

      $title = $_POST['title'];
      $text1 = $_POST['text1'];
      $text2 = $_POST['text2'];

//check if (title) field is empty then print error message.
              if(!$title){  //this means If the title is really empty.
                     $error = "Error: News title is a required field. Please fill it.";
       
               }// end of if
              elseif ((bool) preg_match('/[0-9]/', $title)) {
                 $error3 = "Error: News title must not contain numbers. Please refill it, with all numbers removed.";
                 
               }

              elseif(!$text1){  //this means If the title is really empty.
                     $error1= "Error: News text1 is a required field. Please fill it.";
            
                }
              elseif ((bool) preg_match('/[0-9]/', $text1)) {
                 $error4 = "Error: News title must not contain numbers. Please refill it, with all numbers removed.";
                 
               } 

              elseif(!$text2){  //this means If the title is really empty.
                     $error2= "Error: News text2 is a required field. Please fill it.";
               
               }      
     elseif ((bool) preg_match('/[0-9]/', $text2)) {
                 $error5 = "Error: News title must not contain numbers. Please refill 
it with all numbers removed.";
}


elseif{$result = mysql_query"UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ",$connect");}


}


          echo "<b>Thank you! News UPDATED Successfully!<br>You'll be redirected to Home Page after (4) Seconds";
          echo "<meta http-equiv=Refresh content=4;url=index.php>";
$done="TRUE";
}
if ($done !="TRUE")
else($newsid)
{
        $result = mysql_query("SELECT * FROM news WHERE newsid='$newsid' ",$connect);
        while($myrow = mysql_fetch_assoc($result))
             {
                $title = $myrow["title"];
                $text1 = $myrow["text1"];
  }              $text2= $myrow["text2"];
?>
<br>
<h3>::Edit News</h3>

<form method="post" action="<?php echo $PHP_SELF ?>">
<input type="hidden" name="newsid" value="<? echo $myrow['newsid']?>">

Title: <input name="title" size="40" maxlength="255" value="<? echo $title; ?>"><?php echo $error ?> <?php echo $error3 ?>
<br>
Text1: <textarea name="text1"  rows="7" cols="30"><? echo $text1; ?></textarea><?php echo $error1 ?> <?php echo $error4 ?>
<br>
Text2: <textarea name="text2" rows="7" cols="30"><? echo $text2; ?></textarea> <?php echo $error2 ?> <?php echo $error5 ?>
<br>
<input type="submit" name="submit" value="Update News">
</form>
<?
              }//end of while loop

  }//end else
?>

 

please tell me as soon as possible

Link to comment
Share on other sites

Do you have an editor with a syntax highlighter?  This should have been easy to spot with one.

yes i am using rapid php but error was not corrected

 

elseif
(

         $result = mysql_query"UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ",$connect");

          echo "<b>Thank you! News UPDATED Successfully!<br>You'll be redirected to Home Page after (4) Seconds";
          echo "<meta http-equiv=Refresh content=4;url=index.php>";
$done="TRUE";
)

is this code is correct?

Link to comment
Share on other sites

 

Make another elseif clause based on database input


elseif(something){

mysql_query("UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ,$connect");

echo "<b>Thank you! News UPDATED Successfully!<br>You'll be redirected to Home Page after (4) Seconds";
          echo "<meta http-equiv=Refresh content=4;url=index.php>";
$done="TRUE";
}

Link to comment
Share on other sites

looking at your code you dont really need the database elseif

 

Find:

elseif{$result = mysql_query"UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ",$connect");}
}

 

replace:

mysql_query("UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ",$connect");

Link to comment
Share on other sites

There was about 12 errors in this script, ive rewritten it for you

 

<title>Edit News</title>

<?php

//LAST UPDATE
// 27-09-2007

include("config.php");

$newsid = $_GET['newsid'];


if(isset($_POST['submit'])){

$title = $_POST['title'];
$text1 = $_POST['text1'];
$text2 = $_POST['text2'];

//check if (title) field is empty then print error message.
if(!$title){  //this means If the title is really empty.
$error = "Error: News title is a required field. Please fill it.";
       
}elseif ((bool) preg_match('/[0-9]/', $title)) {
$error3 = "Error: News title must not contain numbers. Please refill it, with all numbers removed.";
                 
}elseif(!$text1){  //this means If the title is really empty.
$error1= "Error: News text1 is a required field. Please fill it.";
            
}elseif ((bool) preg_match('/[0-9]/', $text1)) {
$error4 = "Error: News title must not contain numbers. Please refill it, with all numbers removed.";
                 
}elseif(!$text2){  //this means If the title is really empty.
$error2= "Error: News text2 is a required field. Please fill it.";
               
}elseif ((bool) preg_match('/[0-9]/', $text2)) {
$error5 = "Error: News title must not contain numbers. Please refill it with all numbers removed.";

}

mysql_query("UPDATE news SET title='{$title}', text1='{$text1}', text2='{$text2}' ",$connect);


}//end if submit


echo "<b>Thank you! News UPDATED Successfully!<br>You'll be redirected to Home Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=index.php>";
$done="TRUE";

if ($done !="TRUE"){

$result = mysql_query("SELECT * FROM news WHERE newsid='{$newsid}' ",$connect);
while($myrow = mysql_fetch_assoc($result)){

$title = $myrow["title"];
$text1 = $myrow["text1"];
$text2= $myrow["text2"];

?>
<br>
<h3>::Edit News</h3>

<form method="post" action="<?php echo $PHP_SELF ?>">
<input type="hidden" name="newsid" value="<? echo $myrow['newsid']?>">

Title: <input name="title" size="40" maxlength="255" value="<? echo $title; ?>"><?php echo $error ?> <?php echo $error3 ?>
<br>
Text1: <textarea name="text1"  rows="7" cols="30"><? echo $text1; ?></textarea><?php echo $error1 ?> <?php echo $error4 ?>
<br>
Text2: <textarea name="text2" rows="7" cols="30"><? echo $text2; ?></textarea> <?php echo $error2 ?> <?php echo $error5 ?>
<br>
<input type="submit" name="submit" value="Update News">
</form>
<?
}//end of while loop

}//end else
?>

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.