如何自动更新现有登录用户的特定行


How to automatic update a specific row from an existing user logged in

例如,当用户登录时,登录后我想自动更新此实际用户的特定行。我该怎么做?好吧,当用户登录时,我要更新的是行点,我想在其中添加一些点,例如 5 点。我尝试了一些示例,但它只是添加了另一行,但不适用于此特定用户

<?php
   session_start();
   include_once 'dbconnect.php';
   if(!isset($_SESSION['user'])){
	  header("Location: index.php");
   }
   $res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
   $userRow=mysql_fetch_array($res);
   // Retrieve data from database 
   $sql="SELECT * FROM users ORDER BY user_points DESC LIMIT 10";
   $result=mysql_query($sql);
   $sql = mysql_query("INSERT INTO `users` (`user_points`) VALUES ('5');");
   // Start looping rows in mysql database.
  print "Top 10 Users! ";
  while($rows=mysql_fetch_array($result)){
    echo $rows['user_name'] . " * " . $rows['user_points'] . " * ";
    // close while loop 
  }
  // close MySQL connection 
  mysql_close();
  $page = $_SERVER['PHP_SELF'];
  $sec = "30";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body bgcolor="#ffffff">
<div id="header">
	<div id="left">
    <label>Bitcoin Rotator</label>
    </div>
    <div id="right">
    	<div id="content">
        	hi' <?php echo $userRow['user_name']; ?>&nbsp;<a href="logout.php?logout">Sign Out</a>
		Welcome Back Your Points <?php echo $userRow['user_points']; ?>
<a href="http://bitcoinrotator.publiadds.org.pt/"> Bitcoin Rotator</a><br /><br />
<style> 
#main {
    width: 70px;
    height: 300px;
    border: 1px solid #c3c3c3;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap;
    -webkit-align-content: center;
    align-content: center;
}
#main div {
    width: 70px;
    height: 70px;
}
</style>
        </div>
    </div>
</div>
<div id="body">
	<a href="http://bitcoinrotator.publiadds.org.pt/faucet/" style="color: rgb(0,255,0)"><font color="FF00CC"; style="color: rgb(0,255,0)" >Click Here</font><font color="FF00CC"> to go on our faucet</font></a>
<br>
<br>
<a href="http://bitcoinrotator.publiadds.org.pt/login-registration/get all points.php/" style="color: rgb(0,255,0)"><font color="FF00CC"; style="color: rgb(0,255,0)" >Click Here</font><font color="FF00CC"> to see the top 10 users!</font></a>
<br>
<br>
<a href="http://bitcoinrotator.publiadds.org.pt/login-registration/urls_rotator.php/" style="color: rgb(0,255,0)"><font color="FF00CC"; style="color: rgb(0,255,0)" >Make Your Rotator </font><font color="FF00CC">Click Here To Start!</font></a>
<br>
<br>
<a href="http://bitcoinrotator.publiadds.org.pt/login-registration/geturlonarray.php/" style="color: rgb(0,255,0)"><font color="FF00CC"; style="color: rgb(0,255,0)" >All The Rotators From Our Website </font><font color="FF00CC">Click Here To Start!</font></a>
<div id="main">
  <div style="background-color:coral;"></div>
  <div style="background-color:lightblue;"></div>
  <div style="background-color:pink;"></div>
</div>
</div>
</body>
</html>

您尝试在每次用户登录时插入值 5你想要的是更新行点的内容您可以通过此命令 SQL 执行此操作

"UPDATE `users` SET points=`points`+5 WHERE user_id='".$_SESSION['user']."'"
您需要

的查询是

$user_id = mysql_real_escape_string($_SESSION['user']);
$sql = mysql_query("UPDATE `users` SET user_points = user_points + 5 WHERE user_id = " . $user_id);

请不要使用mysql_库,因为它已被弃用(改用mysqli_