Java: Why a Set Can Contain Duplicate Elements

In low-latency applications, the creation of unnecessary objects is often avoided by reusing mutable objects to reduce memory pressure and thus the load on the garbage collector. This makes the application run much more deterministically and with much less jitter. However, care must be taken as to how these reused objects are used, or else unexpected results might manifest themselves, for example in the form of a Set containing duplicate elements such as [B, B].

HashCode and Equals

Java’s built-in ByteBuffer provides direct access to heap and native memory using 32-bit addressing. Chronicle Bytes is a 64-bit addressing open-source drop-in replacement allowing much larger memory segments to be addressed. Both these types provide a hashCode() and an equals() method that depends on the byte contents of the objects’ underlying memory segment. While this can be useful in many situations, mutable objects like these should not be used in most of Java’s built-in Set types and not as a key in most built-in Map types.

PHP unlink(); No such file or directory

hello, i have a probelm where i want to update my image in database using unlink(). The error is Warning: unlink(images/481933.jpg): No such file or directory. I try search the solution but nothing can solve my probelm. anyone can help me? thank you in advanced. this is my code:

$upload_dir='images/';

$imgExt=strtolower(pathinfo($images,PATHINFO_EXTENSION));

$valid_extensions=array('jpeg', 'jpg', 'png', 'gif', 'pdf');

$picProfile=rand(1000, 1000000).".".$imgExt;

unlink($upload_dir.$edit_row['prod_img']);

move_uploaded_file($tmp_dir, $upload_dir.$picProfile);

$stmt=$db_conn->prepare('UPDATE product SET prod_name=:prod_name, category=:category, prod_img=:prod_img, unit_price=:price, stock=:stock, min_limit=:min_limit, weight=:weight, description=:description, packaging=:packaging, size=:size, retail_price=:retail, agent_price=:agent WHERE prod_id=:prod_id');

Importing a CSV file with hex data.

I have a table with the following fields:

CREATE TABLE text (
    drawing INT NOT NULL,
    blockID INT NOT NULL,
    entityID INT NOT NULL,
    style INT,
    txt VARCHAR(255) NOT NULL,
    attrib INT);

My csv file contains the data:

19  1CB2    E49 2   CLIENT MODULAR  1C2A
19  1CB3    E4B 2   CLIENT UG - 2 MODULAR PILOT PLANT   1C2C
19  1CB4    E4C 2   100 - 500 MICRON    1C2D
19  -1  E50 2   USERNAME    1C31
19  1CBA    E51 2   15.8.2020   1C32
19  1C16    E58 2   PLANT   1C39

I'm using the following SQL to import the CSV file:

LOAD DATA INFILE '/tmp/_P2.8Q9nJ4_/text' INTO TABLE text (drawing,@blockID,@entityID,style,txt,@attrib) SET blockID=UNHEX(@blockID),entityID=UNHEX(@entityID),attrib=UNHEX(@attrib);

But this is the result:

+---------+---------+----------+-------+-------------------------------------------+--------+
| drawing | blockID | entityID | style | txt                                       | attrib |
+---------+---------+----------+-------+-------------------------------------------+--------+
|      19 |       0 |        0 |     0 | CLIENT MODULAR                            |      0 |
|      19 |       0 |        0 |     0 | CLIENT UG - 2 MODULAR PILOT PLANT         |      0 |
|      19 |       0 |        0 |     2 | 100 - 500 MICRON                          |      0 |
|      19 |       0 |        0 |     2 | USERNAME                                  |      0 |
|      19 |       0 |        0 |     2 | PLANT                                     |      0 |
|      19 |       0 |        0 |     2 | 15.8.2020                                 |      0 |

What is the correct way to import a CSV file into my table?

I am trying to avoid duplicate usernames and emails

                        **my functions.php file**
                                                 <?php
                                                 function confirmquery( $result ){
                                                     global $db;
                                                     if(!$result){
                                                        die("OUERY FAILED .".mysqli_error($db));
                                                      }
                                                }

                                                function redirect($location){
                                                  return header("Location:". $location);
                                                }

                                                function is_admin($username = ''){
                                                    global $db;
                                                    $sql = "SELECT user_role FROM users WHERE username = '$username'";
                                                    $result = mysqli_query($db, $sql);
                                                    confirmquery( $result );
                                                 $row = mysqli_fetch_array($result);
                                                     if ($row['user_role'] == 'admin') {
                                                       return true;
                                                     }else {
                                                       return false;
                                                     }
                                                }

                                                function username_exists($username = ''){
                                                    global $db;
                                                    $sql = "SELECT 'username' FROM users WHERE 'username' = '$username'";
                                                    $result = mysqli_query($db, $sql);
                                                    confirmquery( $result );

                                                      if (mysqli_num_rows($result) > 0) {
                                                        return true;
                                                      }else {
                                                        return false;
                                                      }
                                                }

                                                function email_exists($user_email = ''){
                                                    global $db;
                                                    $sql = "SELECT 'user_email' FROM users WHERE 'user_email' = '$user_email'";
                                                    $result = mysqli_query($db, $sql);
                                                    confirmquery( $result );

                                                     if (mysqli_num_rows($result) > 0) {
                                                       return true;
                                                     }else {
                                                       return false;
                                                     }
                                                }

                                                function recordCount($table){
                                                    global $db;
                                                  $sql    =" SELECT * FROM ".$table;
                                                  $result = mysqli_query($db, $sql);
                                                  return  mysqli_num_rows($result);

                                                }

                                                function register_user($username,$user_email,$user_password){
                                                  global $db;

                                                    $username     =mysqli_real_escape_string($db,$username);
                                                    $user_email   =mysqli_real_escape_string($db,$user_email);
                                                    $user_password=mysqli_real_escape_string($db,$user_password);

                                                    $user_password = password_hash($user_password, PASSWORD_BCRYPT, array('COST' => 12 ));

                                                    $sql="INSERT INTO `users`
                                                              SET

                                                            `username`         ='{$username}',
                                                            `user_email`       ='{$user_email}',
                                                            `user_password`    ='{$user_password}',
                                                            `user_role`        ='user'";

                                                      $result = mysqli_query($db, $sql);
                                                      confirmquery( $result );

                                                }

                                                function login_user($user_email, $user_password){
                                                      global $db;
                                                      $user_email    =trim($user_email);
                                                      $user_password =trim($user_password);

                                                      $user_email = mysqli_real_escape_string($db,$user_email);
                                                      $user_password = mysqli_real_escape_string($db,$user_password);

                                                 $sql = "SELECT * FROM `users` WHERE user_email='{$user_email}'";
                                                 $result = mysqli_query($db, $sql);
                                                     if(!$result){
                                                         die("OUERY FAILED .".mysqli_error($db));
                                                       }

                                                  while($row = mysqli_fetch_array($result)){
                                                     $db_user_id = $row['user_id'];
                                                     $db_username = $row['username'];
                                                     $db_user_email = $row['user_email'];
                                                     $db_user_password = $row['user_password'];
                                                     $db_user_firstname = $row['user_firstname'];
                                                     $db_user_lastname = $row['user_lastname'];
                                                     $db_user_role= $row['user_role'];
                                                     }
                                                    // $user_password = crypt($user_password,$db_user_password);

                                                if (password_verify($user_password, $db_user_password)) {
                                                $_SESSION['db_username']       = $db_username;
                                                $_SESSION['db_user_firstname'] = $db_user_firstname;
                                                $_SESSION['db_user_lastname']  = $db_user_lastname;
                                                $_SESSION['db_user_role']      = $db_user_role;

                                                  redirect("/gms/index.php");
                                                }

                                                }

                                                 ?>

                             **My registration.php file**     

                        <?php   include "includes/connect.php"; ?>
                        <?php  include "includes/header.php"; ?>
                        <?php  include "./admin/functions.php"; ?>

                         <?php
                             if ($_SERVER['REQUEST_METHOD'] == "POST") {
                              $username      =trim($_POST['username']);
                              $user_email    =trim($_POST['email']);
                              $user_password =trim($_POST['password']);

                              $error = [
                                'username' => '',
                                'email' => '',
                                'password' => ''
                              ];

                              if(strlen($username) < 4){
                                $error['username'] = 'Username needs to be longer';
                              }

                              if($username == ''){
                                $error['username'] = 'Username cannot be empty';
                              }

                              if(username_exists($username)){
                                $error['username'] = 'Username already exists';
                              }

                              if($user_email == ''){
                                $error['email'] = 'Email cannot be empty';
                              }

                              if(email_exists($user_email)){
                                $error['email'] = 'Email already exists, <a href = "index.php">Please login</a>';
                              }

                              if($user_password == ''){
                                $error['password'] = 'Password cannot be empty';
                              }

                              foreach ($error as $key => $value) {
                                if(empty($value)){
                                  unset($error[$key]);
                                  }
                                }

                                if(empty($error)){
                                  register_user($username, $user_email, $user_password);
                                  login_user($user_email, $user_password );
                                }

                            }

                          ?>

                            <!-- Navigation -->

                            <?php  include "includes/navigation.php"; ?>

                            <!-- Page Content -->
                            <div class="container">

                        <section id="login">
                            <div class="container">
                                <div class="row">
                                    <div class="col-xs-6 col-xs-offset-3">
                                        <div class="form-wrap">
                                        <h1>Register</h1>
                                            <form role="form" action="registration.php" method="post" id="login-form" autocomplete="oFF">

                                                <div class="form-group">
                                                    <label for="username" class="sr-only">username</label>
                                                    <input type="text" name="username" id="username" class="form-control" placeholder="Enter Desired Username"
                                                      autocomplete="on"
                                                      value = "<?php echo isset($username) ? $username : '' ?>"  >
                                                      <p><?php echo isset($error['username']) ? $error['username'] : '' ?></p>

                                                </div>
                                                 <div class="form-group">
                                                    <label for="email" class="sr-only">Email</label>
                                                    <input type="email" name="email" id="email" class="form-control" placeholder="somebody@example.com"

                                                    value = "<?php echo isset($user_email) ? $user_email : '' ?>">
                                                    <p><?php echo isset($error['email']) ? $error['email'] : '' ?></p>

                                                </div>
                                                 <div class="form-group">
                                                    <label for="password" class="sr-only">Password</label>
                                                    <input type="password" name="password" id="key" class="form-control" placeholder="Password">

                                                    <p><?php echo isset($error['password']) ? $error['password'] : '' ?></p>

                                                </div>

                                                <input type="submit" name="register" id="btn-login" class="btn btn-custom btn-lg btn-block" value="Register">
                                            </form>

                                        </div>
                                    </div> <!-- /.col-xs-12 -->
                                </div> <!-- /.row -->
                            </div> <!-- /.container -->
                        </section>

                                <hr>

                        <?php include "includes/footer.php";?>

Session variable is not updated when database gets updated

Hello,
So I have buttons on my site connected to a PHP code that updates the column "status" in "users" table with a value based on what button you press.
This is the PHP script for that:

<?php

include('functions.php');

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "emildeveloping";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$id = $_SESSION['user']['id'];

if (isset($_POST['108'])) {
$sql = "UPDATE users SET status = '10-8' WHERE id='".$id."'";
}

if (isset($_POST['107'])) {
    $sql = "UPDATE users SET status = '10-7' WHERE id='".$id."'";
    }

    if (isset($_POST['105'])) {
        $sql = "UPDATE users SET status = '10-5' WHERE id='".$id."'";
        }

        if (isset($_POST['1015'])) {
            $sql = "UPDATE users SET status = '10-15' WHERE id='".$id."'";
            }

            if (isset($_POST['1023'])) {
                $sql = "UPDATE users SET status = '10-23' WHERE id='".$id."'";
                }

                if (isset($_POST['1097'])) {
                    $sql = "UPDATE users SET status = '10-97' WHERE id='".$id."'";
                    }

                    if (isset($_POST['1042'])) {
                        $sql = "UPDATE users SET status = '10-42' WHERE id='".$id."'";
                        }

if (mysqli_query($conn, $sql)) {
    echo "Status was updated.";
    header( "refresh:2;url=index.php" );
} else {
    echo "Error: " . mysqli_error($conn);
}

mysqli_close($conn);
?>

And this is the HTML snippet with buttons:

 <form  method="post" action="status.php">
   <input type="submit" class="submit-108" name="108" value="10-8">
</form>

<form  method="post" action="status.php">
   <input type="submit" class="submit-107" name="107" value="10-7">
   </form>

   <form  method="post" action="status.php">
   <input type="submit" class="submit-105" name="105" value="10-5">
   </form>

   <form  method="post" action="status.php">
   <input type="submit" class="submit-1015" name="1015" value="10-15">
   </form>

   <form  method="post" action="status.php">
   <input type="submit" class="submit-1023" name="1023" value="10-23">
   </form>

   <form  method="post" action="status.php">
   <input type="submit" class="submit-1097" name="1097" value="10-97">
   </form>

 <form  method="post" action="status.php">
   <input type="submit" class="submit-1042" name="1042" value="10-42">
   </form>

This part works fine, the column gets updated and so on.
The thing is that I have a div on my site that have a php snippet in it that displays the data from the status column with session variable.
And this div dosen't update when I have updated the column status and refreshes the page?
How can I make this happen?
The HTML snippet for displaying the status column:

 <div id="status" class="status"><b>My Status: </b><font color="#6195ff"><?php echo $_SESSION['user']['status']; ?></div></font>

Best Regards Emil