Hi Have Start A new Program That Need To update user_points row by ajax my code is
<?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
$user_id = mysql_real_escape_string($_SESSION['user']);
$sql = mysql_query("UPDATE `users` SET user_points = user_points +'$user_points' WHERE user_id = " . $_SESSION['user']);
// close MySQL connection
mysql_close();
?>
<!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="0;URL= http://mywebsite/login-registration/home.php">
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body bgcolor="#ffffff">
</body>
</html>
How can i setup the correct query to send the data to database i want to update the user_points by ajax the info its send from other app this app go to send the user_points by ajax to the php and php go to update the user points
</div>
<?php
session_start();
include_once 'dbconnect.php';
if(!isset($_POST['user']))
{
header("Location: index.php");
die();
}
$user_id = mysql_real_escape_string($_POST['user']);
$res=mysql_query("SELECT * FROM users WHERE user_id=$user_id");
$userRow=mysql_fetch_array($res);
// Retrieve data from database
$sql = mysql_query("UPDATE `users` SET user_points = user_points +1 WHERE user_id = $user_id");
// close MySQL connection
mysql_close();
?>
$user_ponts
isn't defined in your code. Further you should use the escaped $user_id
in your SQL statements. Additionally you should use die
after the header redirection to prevent the rest of the code from being executed. Further $_SESSION is probably not what you want to use for an ajax call. You could use $_POST instead.
</div>