PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Mar 23, 2017 9:10 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Mar 18, 2017 7:39 pm 
Offline
Forum Commoner

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 32
Hiya Folks,

Why is not mysql getting UPDATED, do you reckon ?

Syntax: [ Download ] [ Hide ]
<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 $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&gt;Welcome <b>&lt;h2&gt;$db_forename $db_surname!&lt;/center&gt;"?&gt;&lt;/h2&gt;</b>|

                &lt;?php
                //Display log-out link.
                echo "&lt;p align=&#39;right&#39;&gt;&lt;a href=&#39;logout.php&#39;&gt;$user Log Out&lt;/a&gt;";?&gt;|&lt;/p&gt;&lt;br&gt;
       
                &lt;form method="post" action=""&gt;   
                &lt;div class="form-group"&gt;
                &lt;center&gt;&lt;label&gt;Post Status To Friends:&lt;/label&gt;
                &lt;input type="text" placeholder="Post Status To Friends" name="post_status_to_friends" /&gt;&lt;/center&gt;&lt;br&gt;
                &lt;center&gt;&lt;button type="submit" class="btn btn-default" name="post_status_to_friends" /&gt;Post Status To Friends!&lt;/button&gt;&lt;/center&gt;
                &lt;/div&gt;
                &lt;/form&gt;&lt;br&gt;
                &lt;br&gt;
                &lt;form method="post" action=""&gt;
                &lt;div class="form-group"&gt;
                &lt;center&gt;&lt;label&gt;Post Status To Public:&lt;/label&gt;
                &lt;input type="text" placeholder="Post Status To Public" name="post_status_to_public" /&gt;&lt;/center&gt;&lt;br&gt;
                &lt;center&gt;&lt;button type="submit" class="btn btn-default" name="post_status_to_public" /&gt;Post Status To Public!&lt;/button&gt;&lt;/center&gt;
                &lt;/div&gt;
                &lt;/form&gt;
                &lt;?php
                //Post User Status To Friends in $user table.
               
                if  &#40;isset&#40;$_POST[&#39;post_status_to_friends&#39;]&#41;&#41;
                {
                        $status_to_friends = trim&#40;$_POST["post_status_to_friends"]&#41;;
                        $status_to_friends = mysqli_real_escape_string&#40;$conn,$status_to_friends&#41;;
               
                        $sql = "UPDATE $user SET Status_To_Friends "$db_status_to_friends" WHERE Username = &#39;".$user."&#39;";
                        if&#40;$conn-&gt;query&#40;$sql&#41;===TRUE&#41;
                        {
                                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 = &#39;".$user."&#39;";
                        if&#40;$conn-&gt;query&#40;$sql&#41;===TRUE&#41;
                        {
                                echo "posted status for friends to users table!";
                        }
                        else    
                        {
                                echo "posting status for friends to users table failed!";
                        }
        }
                ?&gt;&lt;br&gt;
                &lt;br&gt;
                       
                &lt;?php
                //Post User Status To Public in $user table.
       
                if  &#40;isset&#40;$_POST[&#39;post_status_to_public&#39;]&#41;&#41;
                {
                        $status_to_public = trim&#40;$_POST["post_status_to_public"]&#41;;
                        $status_to_public = mysqli_real_escape_string&#40;$conn,$status_to_public&#41;;
               
                        $sql = "UPDATE $user SET Status_To_Public "$db_status_to_public" WHERE Username = &#39;".$user."&#39;";
                        if&#40;$conn-&gt;query&#40;$sql&#41;===TRUE&#41;
                        {
                                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 = &#39;".$user."&#39;";
                        if&#40;$conn-&gt;query&#40;$sql&#41;===TRUE&#41;
                        {
                                echo "posted status for public to users table!";
                        }
                        else    
                        {
                                echo "posting status for public to users table failed!";
                        }                              
                }
                ?&gt;&lt;br&gt;
                &lt;br&gt;
                       
        &lt;?php
        //Display User Status To Friends. Search for User&#39;s data with $user.
                       
        $query = "SELECT * FROM $user WHERE Username = &#39;".$user."&#39;";
        $result = mysqli_query&#40;$conn,$query&#41;;
        $numrows = mysqli_num_rows&#40;$result&#41;;
        if&#40;$numrows = 0&#41;
        {              
                echo "No data!";
        }
        else
        {
                while&#40;$row = mysqli_fetch_assoc&#40;$result&#41;&#41;
                {        
                        $db_status_to_friends = $row["Status_To_Friends"];
                }
                echo "&lt;br&gt;<b>$user Status To Friends:</b>&lt;br&gt;
                $db_status_to_friends"
;
                }
        }
        ?&gt;&lt;br&gt;
        &lt;br&gt;
               
        &lt;?php
        //Display User Status To Public. Search for User&#39;s data with $user.
        $query = "SELECT * FROM $user WHERE Username = &#39;".$user."&#39;";
        $result = mysqli_query&#40;$conn,$query&#41;;
        $numrows = mysqli_num_rows&#40;$result&#41;;
        if&#40;$numrows = 0&#41;
        {              
                echo "No data!";
        }
        else
        {
                while&#40;$row = mysqli_fetch_assoc&#40;$result&#41;&#41;
                {        
                        $db_status_to_public = $row["Status_To_Public"];
                }
                echo "&lt;br&gt;<b>$user Status To Public:</b>&lt;br&gt;
                $db_status_to_public"
;
        }
        ?&gt;&lt;br&gt;
        &lt;br&gt;
                       
        &lt;?php
        //Display User&#39;s Latest View.
        echo "&lt;br&gt;<b>Latest View:</b>&lt;br&gt;";
        echo "$db_latest_view";?&gt;&lt;br&gt;
        &lt;br&gt;

        &lt;?php
        //Display User&#39;s Latest Viewed Url in iFrame.?&gt;
        &lt;iframe src="&lt;?php echo $db_latest_view;?&gt;"&gt;&lt;/iframe&gt;
       
        &lt;?php
        //Display User Bio.
        echo "&lt;br&gt;<b>Bio:</b>&lt;br&gt;";
        echo "$db_bio";?&gt;&lt;br&gt;
        &lt;br&gt;
       
        &lt;?php
}

?&gt;

&lt;/body&gt;
&lt;/html&gt;


Top
 Profile  
 
PostPosted: Sat Mar 18, 2017 11:53 pm 
Offline
Forum Contributor

Joined: Fri Jul 20, 2007 11:29 am
Posts: 320
http://catb.org/~esr/faqs/smart-questions.html#intro

Reduce your code example to the bare minimum.

_________________
Warning: I have no idea what I'm talking about.


Top
 Profile  
 
PostPosted: Sun Mar 19, 2017 7:20 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6187
Location: Montreal, Canada
thinsoldier wrote:
http://catb.org/~esr/faqs/smart-questions.html#intro

Reduce your code example to the bare minimum.

+1

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Sun Mar 19, 2017 3:51 pm 
Offline
Forum Contributor

Joined: Fri Jul 20, 2007 11:29 am
Posts: 320
Why is your markup coming out as html entities?

Are you copying and pasting from a really old version of Dreamweaver?

Syntax: [ Download ] [ Hide ]
<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 $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 "<center>Welcome <h2>$db_forename $db_surname!</center>"?></h2>|

                <?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><br>
                <br>
                <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>
                </form>
                <?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!";
                        }
        }
                ?><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);
               
                        $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!";
                        }                              
                }
                ?><br>
                <br>
                       
        <?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 "<br>$user Status To Friends:<br>
                $db_status_to_friends"
;
                }
        }
        ?><br>
        <br>
               
        <?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 "<br>$user Status To Public:<br>
                $db_status_to_public"
;
        }
        ?><br>
        <br>
                       
        <?php
        //Display User's Latest View.
        echo "<br>Latest View:<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
        //Display User Bio.
        echo "<br>Bio:<br>";
        echo "$db_bio";?><br>
        <br>
       
        <?php
}

?>

</body>
</html>
 

_________________
Warning: I have no idea what I'm talking about.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group