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

Thread: Why is not mysql getting UPDATED ?

  1. #1
    Join Date
    Oct 2016
    Posts
    109

    Question Why is not mysql getting UPDATED ?

    Hiya Folks,

    Why is not mysql getting UPDATED, do you reckon ?

    PHP Code:

    <html>
    &
    lt;head>
    &
    lt;title>
    &
    lt;?php 
    $user
    ?&gtHome Page
    </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&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='right'&gt;&lt;a href='logout.php'&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  (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-&gt;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-&gt;query($sql)===TRUE)
                {
                    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  (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-&gt;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-&gt;query($sql)===TRUE)
                {
                    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'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&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'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&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'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'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

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,978
    No way to make sense of that code with all the HTML character entities in there ("&lt;", etc.).
    "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
    109
    PHP Code:
    <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 <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><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><b>$user Status To Friends:</b><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><b>$user Status To Public:</b><br>
            
    $db_status_to_public";
        }
        
    ?><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 
        
    //Display User Bio.
        
    echo "<br><b>Bio:</b><br>";
        echo 
    "$db_bio";?><br>
        <br>
        
        <?php 
    }

    ?>

    </body>
    </html>

  4. #4
    Join Date
    Oct 2016
    Posts
    109
    I do not know what created all those stuffs during copying from NotePad++ and pasting in the forum thread.


    &lt;html&gt;
    &lt;head&gt;
    &lt;title&gt;
    &lt;?php
    $user?&gt; Home Page
    &lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;

  5. #5
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,766
    Yes - your format is ugly. Is this something you deliberately did or did it get translated by something you did in posting it here? That and the arrangement of your code doesn't help either. Develop a good habit of putting you PHP at the beginning of a script and your html after all of that. Keep them separate to help with readability and maintenance and understanding.

    As for your question - is your db table really named for the current user, ie, you have separate tables for each and every user instead of one table with a row for each and every user? I didn't go any further once I had that question.
    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!

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,766
    Hmmm..
    OP,
    I received an email saying you made a post, but I don't see it here.
    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!

  7. #7
    Join Date
    Oct 2016
    Posts
    109
    Quote Originally Posted by ginerjm View Post
    Yes - your format is ugly. Is this something you deliberately did or did it get translated by something you did in posting it here? That and the arrangement of your code doesn't help either. Develop a good habit of putting you PHP at the beginning of a script and your html after all of that. Keep them separate to help with readability and maintenance and understanding.

    As for your question - is your db table really named for the current user, ie, you have separate tables for each and every user instead of one table with a row for each and every user? I didn't go any further once I had that question.
    Something, maybe this forum, made all those ugly stuffs and not me.
    Yes, script creates table for each every user. I have my reasons for that and once the full script is complete you'll understand why.

  8. #8
    Join Date
    Oct 2013
    Location
    Sheboygan, Wisconsin
    Posts
    1,387
    Do me a favour and attach a text file with your original code PLEASE!

    I want to do some testing.
    Last edited by Train; 03-20-2017 at 10:20 AM.

  9. #9
    Join Date
    Mar 2017
    Posts
    14
    I am not able to find what the problem is. I hope the names of the tables and database mentioned are correct.

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