0

I have this set of php and im getting this error, not sure how to fix it tho, seems like a simple fix, think I have just been up to long running on tea lol.

Parse error: syntax error, unexpected ')' LINE 148

Please post if you can help and thanks in advance.

<!DOCTYPE HTML>
<html>
<head>
<link type="text/css" rel="stylesheet" href="../css/post.css" />

<meta name="viewport" content="width=device-width" />
<title>Daily Dorm News</title>
</head>

<body>
<h1>Your Daily Dorm News Post! </h1>
<div id="container"> <?php if ( isset($_GET['name']) and preg_match("/^[A-Za-z0-9]+$/", $_GET['name']) ) {

    echo $_GET['name'];

} else {

    echo "You entered an invalid name!\n";

}

?><br>


Your email address is: <?php if ( isset($_GET['email']) and preg_match("/.+@.+\..+/i", $_GET['email']) ) {

    echo $_GET['email'];

} else {

    echo "You didn't enter a proper email address!\n";

}
?><br>
You Posted : <?php if ( isset($_GET['message']) and preg_match("/^[-\.a-zA-Z\s0-9]+$/", $_GET['message']) ) {

    echo $_GET['message'];

} else {

    echo "The message is not valid! The message box was blank or you entered invalid symbols!\n";

}
?>

This event happened :<?php echo $_GET["date"]; ?><br>


</div>

<?php
/* [INFO/CS 1300 Project 3] index.php
 * Main page for our app.
 * Shows all previous posts and highlights the current user's post, if any.
* Includes a link to form.php if user wishes to create and submit a post.
*/

require('wall_database.php');

// Fetching data from the request sent by form.php  
$name = strip_tags($_REQUEST['name']);
$email = strip_tags($_REQUEST['email']);
$message = strip_tags($_REQUEST['message']);
$date = strip_tags($_REQUEST['date']);
$is_valid_post = true;
// Checking if a form was submitted
if (isset($_REQUEST['name'])){
 // Fetching data from the request sent by form.php  
$name = strip_tags($_REQUEST['name']);
$email = strip_tags($_REQUEST['email']);
$message = strip_tags($_REQUEST['message']);
$date = strip_tags($_REQUEST['date']);  

 // Saving the current post, if a form was submitted
 $post_fields = array();
 $post_fields['name'] = $name;
 $post_fields['email'] = $email;
 $post_fields['message'] = $message;
 $post_fields['date'] = $date;
 $success_flag = saveCurrentPost($post_fields);

}

//Fetching all posts from the database
$posts_array = getAllPosts();

require('header.php');
?>


   <p><a href="../index.php">Submit a Post</a></p>

   <?php
   if(isset($name)) {
     echo "<h3>Thanks ".$name." for submitting your post.</h3>";
   }
   ?>

   <p>Here are all the posts we have received.</p>
   <ul id="posts_list">
   <?php

   // Looping through all the posts in posts_array
   $counter = 1;

   foreach(array_reverse($posts_array) as $post){
     $name = $post['name'];
     $email = $post['email'];
     $message = $post['message'];
     $date = $post['date'];

     if ($counter % 2==1)
       $li_class = "float-left";
     else
       $li_class = "float-right";


        echo '<div class=post>';
        echo '<li class="'.$li_class.'"><h3><span>'.$name.'</span> wrote a post.</h3></li>';
        echo '<li class="'.$li_class.'"><h3><span>'.$name.' email is: '.$email.'</span></h3></li>';
        echo '<li class="'.$li_class.'"><h3><span>'.$name.' wrote '.$message.'</span> wrote a post.</h3></li>';
        echo '<li class="'.$li_class.'"><h3><span>This event occured on '.$date.'</span></h3></li>';

        echo '</div>';
   }
   ?>

</ul>
</div>

<?php 
// Variable for keeping track if a user has posted.  Set to false initially.  If found it will be changed to true.
$alreadyPosted = false;
// Loop through all the posts
foreach ($posts_array as $post) {
 // Check to see if the the person in the database ($post['name']) matches the supplied name ($name)
  if ($post['name'] == $name) {
     // It does.  Great.  Set the variable to true.
  $alreadyPosted = true;
 $alreadyPosted = false;
  }
}?>

<div id="highlight">
<?php
 if ($alreadyPosted ?) {
echo "id="highlight" ;}
  ?>

</div>
</body>
</html>
6
  • The error message gives you a very useful piece of information that you've neglected to tell us, the line number... so you're expecting us to trawl through every line of your code rather than giving us all the information you should Commented Nov 17, 2013 at 1:26
  • Line 148 sorry about that Commented Nov 17, 2013 at 1:26
  • if ($alreadyPosted ?) {.... get rid of that ? Commented Nov 17, 2013 at 1:29
  • then i get Parse error: syntax error, unexpected T_STRING, expecting ',' or '; Line 149 tho Commented Nov 17, 2013 at 1:31
  • echo "id=\"highlight\""; } Commented Nov 17, 2013 at 1:33

2 Answers 2

0
if ($alreadyPosted ?) {

The unexpected ) comes after an unexpected question mark, but the php parser thinks you're trying to make a ternary, so it assumes the parenthesis is the problem.

Sign up to request clarification or add additional context in comments.

10 Comments

how can i fix this tho? wasnt to sure, and i didnt want to mess it up
Just remove the question mark, then fix the quotation marks on the next line.
such like echo "id=highlight" ;}
Or echo 'id="highlight"'; or echo "id='highlight'";
ok its not giving me an error now, but dont I need to set $alreadyposted o true? because I want it so that if the user with that particular name has alreadyposted, then I want it to be highlighted. I have the css as #highlight { background-color:yellow;}
|
0
<div id="highlight">
<?php
 if ($alreadyPosted) {
echo "id='highlight'" ;}
  ?>

Try the following code there and let me know either it was helpful to you or not?

1 Comment

no didnt work, it didnt highlight the post if the same user with same username posted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.