dcsimg
www.webdeveloper.com
Results 1 to 7 of 7

Thread: Why Is The Closing Bracket Black ?

  1. #1
    Join Date
    Oct 2016
    Posts
    118

    Question Why Is The Closing Bracket Black ?

    Howdy,

    On my NotePad++, the line at 116 shows the closing bracket of the ELSE black. Really really puzzling!
    I know my code is not neat but I will tidy it up based on the feedback I got so far but in the meanwhile my great mind is filled with the question why the line at 116 shows the closing bracket of the ELSE black.

    PHP Code:
    <html>
    <head>
    <title>
    $user Home Page
    </title>
    </head>
    <body>
    <body background=".png">

    <?php
    session_start
    ();
    require 
    "conn.php";

    /*Check if user is logged-in or not by checking if session is set or not.*
    If user is not logged-in then redirect to login page. Else, show user's account homepage.*/

    if(!isset($_SESSION["user"]))*
    {
    * * 
    header("location:login.php");
    }
    else*
    {
    * * 
    $user $_SESSION["user"];
    * * 
    $sql "SELECT * FROM users WHERE Username = '".$user."'";
    * * 
    $result $conn->query($sql);
    * * while(
    $row mysqli_fetch_assoc($result))*
    ** *{
    ** * * *
    $db_id $row["Id"];
    ** * * *
    $db_username $row["Username"];
    ** * * *
    $db_forename $row["Forename"];
    ** * * *
    $db_surname $row["Surname"];
    ** * * *
    $db_email $row["Email"];
    ** * * *
    $db_bio $row["Bio"];
    ** * * *
    $db_status $row["Status"];
    * **
    ** *
    ** * * *
    //Welcome user by name.
    ** *** *echo "<center>Welcome <b><h2>$db_forename $db_surname!</center>"?></h2></b>|

    ** *** *<?php
    ** *** *//Display log-out link.
    ** *** *echo "<p align='right'><a href='logout.php'>$user Log Out</a>";?>|</p><br>
    ** *
    ** *** *<form method="post" action="">** *
    ** *** *<div class="form-group">
    ** *** *<center><label>Post Status To Friends:</label>
    ** *** *<input type="text" placeholder="Post Status To Friends" name="post_status_to_friends" /></center><br>
    ** *** *<center><button type="submit" class="btn btn-default" name="post_status_to_friends" />Post Status To Friends!</button></center>
    ** *** *</div>

    ** *** *<form method="post" action="">
    ** *** *<div class="form-group">
    ** *** *<center><label>Post Status To Public:</label>
    ** *** *<input type="text" placeholder="Post Status To Public" name="post_status_to_public" /></center><br>
    ** *** *<center><button type="submit" class="btn btn-default" name="post_status_to_public" />Post Status To Public!</button></center>
    ** *** *</div>
    ** *
    ** *** *<?php
    ** *** *//Post User Status To Friends in $user table.
    ** *** *
    ** *** *if *(isset(
    $_POST['post_status_to_friends']))
    ** *** *{
    ** *** *** *
    $status_to_friends trim($_POST["post_status_to_friends"]);
    ** *** *** *
    $status_to_friends mysqli_real_escape_string($conn,$status_to_friends);
    ** *** *
    ** *** *** *
    $conn->query("UPDATE $user SET Status_To_Friends $status_to_friends WHERE Username = '".$user."'");
    ** *** *** *if(
    $conn->query($sql)===TRUE)
    ** *** *** *{
    ** *** *** *** *echo 
    "posted status for friends to $user table!";
    ** *** *** *** *
    $conn->close();
    ** *** *** *** *exit();
    ** *** *** *}
    ** *** *** *else * *
    ** *** *** *{
    ** *** *** *** *echo 
    "posting status for friends to $user table failed!";
    ** *** *** *** *
    $conn->close();
    ** *** *** *** *exit();
    ** *** *** *}
    ** *
    ** *** *** *
    //Post User Status To Friends in "users" table.
    ** *** *
    ** *** *** *
    $conn->query("UPDATE users SET Status_To_Friends $status_to_friends WHERE Username = '".$user."'");
    ** *** *** *if(
    $conn->query($sql)===TRUE)
    ** *** *** *{
    ** *** *** *** *echo 
    "posted status for friends to users table!";
    ** *** *** *** *
    $conn->close();
    ** *** *** *** *exit();
    ** *** *** *}
    ** *** *** *else * *
    ** *** *** *{
    ** *** *** *** *echo 
    "posting status for friends to users table failed!";
    ** *** *** *** *
    $conn->close();
    ** *** *** *** *exit();
    ** *** *** *}
    * * ** *
    ** *** *** *
    //Display User Status To Friends. Search for User's data with $user.
    ** *** *** *
    ** *** *** *
    $query "SELECT * FROM $user WHERE Username = '".$user."'";
    ** *** *** *
    $result mysqli_query($conn,$query);
    ** *** *** *
    $numrows mysqli_num_rows($result);
    ** *** *** *if(
    $numrows 0)
    ** *** *** *{** *** *
    ** *** *** *** *echo 
    "No data!";
    ** *** *** *** *
    $conn->close();
    ** *** *** *** *exit();
    ** *** *** *}
    ** *** *** *else*
    ** *** *** *{
    ** *** *** *** *while(
    $row mysqli_fetch_assoc($result))*
    ** *** *** *** *{** * *
    ** *** *** *** *** *
    $db_status_to_friends $row["Status_To_Friends"];
    ** *** *** *** *}
    ** *** *** * * *echo 
    "<br><b>$user Status To Friends:</b><br>
    ** *** *** * * *
    $db_status_to_friends";?><br>
    ** *** *** * * *<br>
    ** *** *** *}
    ** *
    ** *** *<?php
    ** *** *//Post User Status To Public in $user table.
    ** *
    ** *** *if *(isset(
    $_POST['post_status_to_public']))
    ** *** *{
    ** *** *** *
    $status_to_public trim($_POST["post_status_to_public"]);
    ** *** *** *
    $status_to_public mysqli_real_escape_string($conn,$status_to_public);
    ** *** *
    ** *** *** *
    $conn->query("UPDATE $user SET Status_To_Public $status_to_public WHERE Username = '".$user."'");
    ** *** *** *if(
    $conn->query($sql)===TRUE)
    ** *** *** *{
    ** *** *** *** *echo 
    "posted status for public to $user table!";
    ** *** *** *** *
    $conn->close();
    ** *** *** *** *exit();
    ** *** *** *}
    ** *** *** *else * *
    ** *** *** *{
    ** *** *** *** *echo 
    "posting status for public to $user table failed!";
    ** *** *** *** *
    $conn->close();
    ** *** *** *** *exit();
    ** *** *** *}
    ** *
    ** *** *** *
    //Post User Status To Public in users table.
    ** *** *** *$conn->query("UPDATE users SET Status_To_Public $status_to_public WHERE Username = '".$user."'");
    ** *** *** *if(
    $conn->query($sql)===TRUE)
    ** *** *** *{
    ** *** *** *** *echo 
    "posted status for public to users table!";
    ** *** *** *** *
    $conn->close();
    ** *** *** *** *exit();
    ** *** *** *}
    ** *** *** *else * *
    ** *** *** *{
    ** *** *** *** *echo 
    "posting status for public to users table failed!";
    ** *** *** *** *
    $conn->close();
    ** *** *** *** *exit();
    ** *** *** *}
    ** *
    ** *** *** *
    //Display User Status To Public. Search for User's data with $user.
    ** *** *** *
    ** *** *** *
    $query "SELECT * FROM $user WHERE Username = '".$user."'";
    ** *** *** *
    $result mysqli_query($conn,$query);
    ** *** *** *
    $numrows mysqli_num_rows($result);
    ** *** *** *if(
    $numrows 0)
    ** *** *** *{** *** *
    ** *** *** *** *echo 
    "No data!";
    ** *** *** *** *
    $conn->close();
    ** *** *** *** *exit();
    ** *** *** *}
    ** *** *** *else*
    ** *** *** *{
    ** *** *** *** *while(
    $row mysqli_fetch_assoc($result))*
    ** *** *** *** *{** * *
    ** *** *** *** *** *
    $db_status_to_public $row["Status_To_Public"];
    ** *** *** *** *}
    ** *** *** *echo 
    "<br><b>$user Status To Public:</b><br>
    ** *** *** *
    $db_status_to_public";?><br>
    ** *** *** *<br>
    ** *** *** *<?php*
    ** *** *** *}
    ** *** *}
    ** *** *
    ** *** *
    //Display User Bio.
    ** *** *echo "<br><b>Bio:</b><br>";
    ** *** *echo 
    "$db_bio";?><br>
    ** *** *<br>
    ** *** *
    ** *** *<?php*
    ** *** *
    //Display User's Latest View.
    ** *** *echo "<br><b>Latest View:</b><br>";
    ** *** *echo 
    "$db_latest_view";?><br>
    ** *** *<br>

    ** *** *<?php*
    ** *** *
    //Display User's Latest Viewed Url in iFrame.?>
    ** *** *<iframe src="<?php $db_latest_view;?>"></iframe>
    ** *** *<?php ** *
    ** *}
    }
    ?>

    </body>
    </html>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    22,097
    I hope all those asterisks are not actually in your code?

    The problem at line 116 is that the } is not inside of <?php ... ?> tags, so it has no meaning to the PHP intepreter.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Oct 2016
    Posts
    118
    This forum added all those asterisks.
    Pasting code again from NotePad++:

    <html>
    <head>
    <title>
    <?php
    $user?> Home Page
    </title>
    </head>
    <body>
    <body background=".png">

    <?php
    session_start();
    require "conn.php";

    /*Check if user is logged-in or not by checking if session is set or not.
    If user is not logged-in then redirect to login page. Else, show user's account homepage.*/

    if(!isset($_SESSION["user"]))
    {
    header("location:login.php");
    }
    else
    {
    $user = $_SESSION["user"];
    $sql = "SELECT * FROM users WHERE Username = '".$user."'";
    $result = $conn->query($sql);
    while($row = mysqli_fetch_assoc($result))
    {
    $db_id = $row["Id"];
    $db_username = $row["Username"];
    $db_forename = $row["Forename"];
    $db_surname = $row["Surname"];
    $db_email = $row["Email"];
    $db_bio = $row["Bio"];
    $db_status = $row["Status"];


    //Welcome user by name.
    echo "<center>Welcome <b><h2>$db_forename $db_surname!</center>"?></h2></b>|

    <?php
    //Display log-out link.
    echo "<p align='right'><a href='logout.php'>$user Log Out</a>";?>|</p><br>

    <form method="post" action="">
    <div class="form-group">
    <center><label>Post Status To Friends:</label>
    <input type="text" placeholder="Post Status To Friends" name="post_status_to_friends" /></center><br>
    <center><button type="submit" class="btn btn-default" name="post_status_to_friends" />Post Status To Friends!</button></center>
    </div>

    <form method="post" action="">
    <div class="form-group">
    <center><label>Post Status To Public:</label>
    <input type="text" placeholder="Post Status To Public" name="post_status_to_public" /></center><br>
    <center><button type="submit" class="btn btn-default" name="post_status_to_public" />Post Status To Public!</button></center>
    </div>

    <?php
    //Post User Status To Friends in $user table.

    if (isset($_POST['post_status_to_friends']))
    {
    $status_to_friends = trim($_POST["post_status_to_friends"]);
    $status_to_friends = mysqli_real_escape_string($conn,$status_to_friends);

    $conn->query("UPDATE $user SET Status_To_Friends $status_to_friends WHERE Username = '".$user."'");
    if($conn->query($sql)===TRUE)
    {
    echo "posted status for friends to $user table!";
    $conn->close();
    exit();
    }
    else
    {
    echo "posting status for friends to $user table failed!";
    $conn->close();
    exit();
    }

    //Post User Status To Friends in "users" table.

    $conn->query("UPDATE users SET Status_To_Friends $status_to_friends WHERE Username = '".$user."'");
    if($conn->query($sql)===TRUE)
    {
    echo "posted status for friends to users table!";
    $conn->close();
    exit();
    }
    else
    {
    echo "posting status for friends to users table failed!";
    $conn->close();
    exit();
    }

    //Display User Status To Friends. Search for User's data with $user.

    $query = "SELECT * FROM $user WHERE Username = '".$user."'";
    $result = mysqli_query($conn,$query);
    $numrows = mysqli_num_rows($result);
    if($numrows = 0)
    {
    echo "No data!";
    $conn->close();
    exit();
    }
    else
    {
    while($row = mysqli_fetch_assoc($result))
    {
    $db_status_to_friends = $row["Status_To_Friends"];
    }
    echo "<br><b>$user Status To Friends:</b><br>
    $db_status_to_friends";?><br>
    <br>
    }

    <?php
    //Post User Status To Public in $user table.

    if (isset($_POST['post_status_to_public']))
    {
    $status_to_public = trim($_POST["post_status_to_public"]);
    $status_to_public = mysqli_real_escape_string($conn,$status_to_public);

    $conn->query("UPDATE $user SET Status_To_Public $status_to_public WHERE Username = '".$user."'");
    if($conn->query($sql)===TRUE)
    {
    echo "posted status for public to $user table!";
    $conn->close();
    exit();
    }
    else
    {
    echo "posting status for public to $user table failed!";
    $conn->close();
    exit();
    }

    //Post User Status To Public in users table.
    $conn->query("UPDATE users SET Status_To_Public $status_to_public WHERE Username = '".$user."'");
    if($conn->query($sql)===TRUE)
    {
    echo "posted status for public to users table!";
    $conn->close();
    exit();
    }
    else
    {
    echo "posting status for public to users table failed!";
    $conn->close();
    exit();
    }

    //Display User Status To Public. Search for User's data with $user.

    $query = "SELECT * FROM $user WHERE Username = '".$user."'";
    $result = mysqli_query($conn,$query);
    $numrows = mysqli_num_rows($result);
    if($numrows = 0)
    {
    echo "No data!";
    $conn->close();
    exit();
    }
    else
    {
    while($row = mysqli_fetch_assoc($result))
    {
    $db_status_to_public = $row["Status_To_Public"];
    }
    echo "<br><b>$user Status To Public:</b><br>
    $db_status_to_public";?><br>
    <br>
    <?php
    }
    }

    //Display User Bio.
    echo "<br><b>Bio:</b><br>";
    echo "$db_bio";?><br>
    <br>

    <?php
    //Display User's Latest View.
    echo "<br><b>Latest View:</b><br>";
    echo "$db_latest_view";?><br>
    <br>

    <?php
    //Display User's Latest Viewed Url in iFrame.?>
    <iframe src="<?php echo $db_latest_view;?>"></iframe>
    <?php
    }
    }
    ?>

    </body>
    </html>

  4. #4
    Join Date
    Oct 2016
    Posts
    118
    Line 59 has opening php tag and 115 (nearly at the end of the line) has the closing tag. Check again. Everyone keeps missing that. Lol!

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    22,097
    Code:
    echo "<br><b>$user Status To Friends:</b><br>
    $db_status_to_friends";?><br>  <--- closing PHP tag
    <br>
    }                              <--- not in PHP mode, so not parsed as PHP
    
    <?php                          <--- now we're back in PHP mode
    I see it that way, and so does your editor, so you're out-voted 2 to 1.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  6. #6
    Join Date
    Oct 2016
    Posts
    118

    Thumbs up

    Quote Originally Posted by NogDog View Post
    Code:
    echo "<br><b>$user Status To Friends:</b><br>
    $db_status_to_friends";?><br>  <--- closing PHP tag
    <br>
    }                              <--- not in PHP mode, so not parsed as PHP
    
    <?php                          <--- now we're back in PHP mode
    I see it that way, and so does your editor, so you're out-voted 2 to 1.

    Here is my update:

    &lt;html>
    &lt;head>
    &lt;title>
    &lt;?php
    $user?> Home Page
    &lt;/title>
    &lt;/head>
    &lt;body>
    &lt;body background=".png">

    &lt;?php
    session_start();
    require "conn.php";

    /*Check if user is logged-in or not by checking if session is set or not.
    If user is not logged-in then redirect to login page. Else, show user's account homepage.*/

    if(!isset($_SESSION["user"]))
    {
    header("location:login.php");
    }
    else
    {
    $user = $_SESSION["user"];
    $sql = "SELECT * FROM $user WHERE Username = '".$user."'";
    $result = $conn->query($sql);
    while($row = mysqli_fetch_assoc($result))
    {
    $db_id = $row["Id"];
    $db_username = $row["Username"];
    $db_forename = $row["Forename"];
    $db_surname = $row["Surname"];
    $db_email = $row["Email"];
    $db_bio = $row["Bio"];
    $db_status_to_friends = $row["Status_To_Friends"];
    $db_status_to_public = $row["Status_To_Public"];
    $db_latest_view = $row["Latest_View"];

    //Welcome user by name.
    echo "&lt;center>Welcome &lt;h2>$db_forename $db_surname!&lt;/center>"?>&lt;/h2>|

    &lt;?php
    //Display log-out link.
    echo "&lt;p align='right'>&lt;a href='logout.php'>$user Log Out&lt;/a>";?>|&lt;/p>&lt;br>

    &lt;form method="post" action="">
    &lt;div class="form-group">
    &lt;center>&lt;label>Post Status To Friends:&lt;/label>
    &lt;input type="text" placeholder="Post Status To Friends" name="post_status_to_friends" />&lt;/center>&lt;br>
    &lt;center>&lt;button type="submit" class="btn btn-default" name="post_status_to_friends" />Post Status To Friends!&lt;/button>&lt;/center>
    &lt;/div>
    &lt;/form>&lt;br>
    &lt;br>
    &lt;form method="post" action="">
    &lt;div class="form-group">
    &lt;center>&lt;label>Post Status To Public:&lt;/label>
    &lt;input type="text" placeholder="Post Status To Public" name="post_status_to_public" />&lt;/center>&lt;br>
    &lt;center>&lt;button type="submit" class="btn btn-default" name="post_status_to_public" />Post Status To Public!&lt;/button>&lt;/center>
    &lt;/div>
    &lt;/form>
    &lt;?php
    //Post User Status To Friends in $user table.

    if (isset($_POST['post_status_to_friends']))
    {
    $status_to_friends = trim($_POST["post_status_to_friends"]);
    $status_to_friends = mysqli_real_escape_string($conn,$status_to_friends);

    $sql = "UPDATE $user SET Status_To_Friends "$db_status_to_friends" WHERE Username = '".$user."'";
    if($conn->query($sql)===TRUE)
    {
    echo "posted status for friends to $user table!";
    }
    else
    {
    echo "posting status for friends to $user table failed!";
    }

    //Post User Status To Friends in "users" table.

    $sql = "UPDATE users SET Status_To_Friends "$db_status_to_friends" WHERE Username = '".$user."'";
    if($conn->query($sql)===TRUE)
    {
    echo "posted status for friends to users table!";
    }
    else
    {
    echo "posting status for friends to users table failed!";
    }
    }
    ?>&lt;br>
    &lt;br>

    &lt;?php
    //Post User Status To Public in $user table.

    if (isset($_POST['post_status_to_public']))
    {
    $status_to_public = trim($_POST["post_status_to_public"]);
    $status_to_public = mysqli_real_escape_string($conn,$status_to_public);

    $sql = "UPDATE $user SET Status_To_Public "$db_status_to_public" WHERE Username = '".$user."'";
    if($conn->query($sql)===TRUE)
    {
    echo "posted status for public to $user table!";
    }
    else
    {
    echo "posting status for public to $user table failed!";
    }

    //Post User Status To Public in users table.
    $sql = "UPDATE users SET Status_To_Public "$db_status_to_public" WHERE Username = '".$user."'";
    if($conn->query($sql)===TRUE)
    {
    echo "posted status for public to users table!";
    }
    else
    {
    echo "posting status for public to users table failed!";
    }
    }
    ?>&lt;br>
    &lt;br>

    &lt;?php
    //Display User Status To Friends. Search for User's data with $user.

    $query = "SELECT * FROM $user WHERE Username = '".$user."'";
    $result = mysqli_query($conn,$query);
    $numrows = mysqli_num_rows($result);
    if($numrows = 0)
    {
    echo "No data!";
    }
    else
    {
    while($row = mysqli_fetch_assoc($result))
    {
    $db_status_to_friends = $row["Status_To_Friends"];
    }
    echo "&lt;br>$user Status To Friends:&lt;br>
    $db_status_to_friends";
    }
    }
    ?>&lt;br>
    &lt;br>

    &lt;?php
    //Display User Status To Public. Search for User's data with $user.
    $query = "SELECT * FROM $user WHERE Username = '".$user."'";
    $result = mysqli_query($conn,$query);
    $numrows = mysqli_num_rows($result);
    if($numrows = 0)
    {
    echo "No data!";
    }
    else
    {
    while($row = mysqli_fetch_assoc($result))
    {
    $db_status_to_public = $row["Status_To_Public"];
    }
    echo "&lt;br>$user Status To Public:&lt;br>
    $db_status_to_public";
    }
    ?>&lt;br>
    &lt;br>

    &lt;?php
    //Display User's Latest View.
    echo "&lt;br>Latest View:&lt;br>";
    echo "$db_latest_view";?>&lt;br>
    &lt;br>

    &lt;?php
    //Display User's Latest Viewed Url in iFrame.?>
    &lt;iframe src="&lt;?php echo $db_latest_view;?>">&lt;/iframe>

    &lt;?php
    //Display User Bio.
    echo "&lt;br>Bio:&lt;br>";
    echo "$db_bio";?>&lt;br>
    &lt;br>

    &lt;?php
    }

    ?>

    &lt;/body>
    &lt;/html>

    [/php]

  7. #7
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,796
    Please use the proper forum tags when posting your code.

    As for what you have posted. Why all the & chars instead of just plain old normal looking html tags? Are you deliberately doing that or is it being mangled by some process you are uploading it with?
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles