Row disappear each time i update user date [php]

i am using MySQL[duplicated]. i have this problem of mine each time i update user details especially date “username” disappear this is my code

<?php
session_start(); // Starting Session

//check is submit button is click 
if ($_POST['submit']){
    
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("127.0.0.1", "root", "");
$db = mysql_select_db("david_car", $connection);

// collect username and date from textbox
$username = $_POST['username'];
$days = $_POST['days'];

$expire_date = strtotime($days);
$expire = date('y/m/d', $expire_date);
$current_date = date('y/m/d');

// To protect MySQL injection for Security purpose
$username = mysql_real_escape_string($username);

//query database 
$query = mysql_query("UPDATE data_time SET username = '".$_POST['username']."', date_time = '".$expire."', date = '".$current_date."' WHERE username = '".$_SESSION['username']."'  ")or die(mysql_close());
if ($query){
    echo "Updated";
}
    
}

?>

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
html code
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

<html>
<head>
</head>
<body>
<form action="manager.php" method="post">
<label>UserName :</label>
<input id="name" name="username" type="text">
<label>Days :</label>
<input id="name" name="days" type="text">
<input name="submit" type="submit" value="Login">
</form>
</div>
</div>
</body>
</html>

You’ve got a real mix of parameters there. You’re using $_POST but updating based on $_SESSION…are you sure $_SESSION is set?

Also, be REALLY careful updating a database without doing HTML injection projection (which it looks like you’ve got, but not using…)

thanks i gat it working :+1:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.