PHP Session variable not passing - php

I need to pass a variable which called 'square' between my php files, and everything is ok until I go to the action file to retrieve data from my database:
//plan.php
<?php
include("config.php");
session_start();
$loggeduser = $_SESSION['user'];
if (!isset($_SESSION['user']))
{
header("Location: login.php");
}
// Get selected square
$selsquare = $_GET["square"];
?>
<script>
$(document).ready(function(){
fetchUser();
function fetchUser()
{
var action = "Load";
$.ajax({
url : "action.php?square=$selsquare",
method:"POST",
data:{action:action},
success:function(data){
$('#result').html(data);
}
});
}
</script>
and here is my action.php file
<?php
//Database connection by using PHP PDO
$username = 'root';
$password = '';
$connection = new PDO( 'mysql:host=localhost;dbname=db', $username, $password );
$selsquare = $_GET["square"];
if(isset($_POST["action"]))
{
if($_POST["action"] == "Load")
{
$statement = $connection->prepare("SELECT * FROM plans WHERE square = '$selsquare' ");
$statement->execute();
$result = $statement->fetchAll();
$output = '';
$output .= '
<table class="table table-bordered">
<tr>
<th width="10%">ID</th>
<th width="10%">Square</th>
<th width="40%">Plan</th>
<th width="10%">Update</th>
<th width="10%">Delete</th>
</tr>
';
if($statement->rowCount() > 0)
{
foreach($result as $row)
{
$output .= '
<tr>
<td>'.$row["id"].'</td>
<td>'.$row["square"].'</td>
<td>'.$row["plan"].'</td>
<td><button type="button" id="'.$row["id"].'" class="btn btn-warning btn-xs update">Update</button></td>
<td><button type="button" id="'.$row["id"].'" class="btn btn-danger btn-xs delete">Delete</button></td>
</tr>
';
}
}
else
{
$output .= '
<tr>
<td align="center">Data not Found</td>
</tr>
';
}
$output .= '</table>';
echo $output;
}
?>
I need to retrieve all the data that has square = $selsquare but it is not working. The selsquare is working in the plan.php but not in action.php
Please help me figure out whats wrong

You are not doing it correctly. In your ajax method your method of passing data is post and in your action.php file you are fetching it as a get variable.
<script>
$(document).ready(function(){
fetchUser();
function fetchUser()
{
var action = "Load";
var square = "<?php echo $selsquare ?>";
$.ajax({
url : "action.php",
method:"POST",
data:{action:action, square:square},
success:function(data){
$('#result').html(data);
}
});
}
</script>
Now fetch square as post variable in action.php file
I haven't tested the code but it should work.

By default, PHP sessions require a cookie to identify them. You’re trying to run 2 separate PHP scripts (including the script for the Ajax call), so each will need access to the cookie.
Ajax by default doesn’t send cookies. This is a relatively new feature, but is supported in all current browsers.
First, you need to set the property withCredentials to true. This will allow the passing of cookies.
See http://api.jquery.com/jQuery.ajax/
$.ajax({
url: a_cross_domain_url,
xhrFields: {
withCredentials: true
}
});
In PHP, you will also need to include a statement like:
header("Access-Control-Allow-Credentials: true");
in your responding script.
Alternatively, you can instruct PHP to accept the session id and get Ajax to send it as a query string.

You are sending POST from Javascript, while in your PHP you are reading as $_GET.
<script>
$(document).ready(function(){
fetchUser();
function fetchUser()
{
var square_js = '<?php echo $selsquare; ?> ';
$.ajax({
url : "action.php?square=$selsquare",
method:"GET",
data:{square:square_js},
success:function(data){
$('#result').html(data);
}
});
}
</script>
If your square has the value ABCDEF, then in your PHP, you will get the request this way
print_r($_GET);
Array{
"square" => "ABCDEF"
}
Recommended way of passing string in double quote is with {}
url : "action.php?square=$selsquare",
Should be
url : "action.php?square={$selsquare}",

Related

Retrieve data from mysql table ajax

I have an input field with the date type, and there is a database that contains data with dates. I need that when selecting a date in the date field without refreshing the page, all the data associated with this date will be displayed. I have this code, which, when choosing an option from the list, will display what I need. how to fix this script so that when a date is selected in a date type field, it sends the date to the server
<input type="date" class="form-control" name="date_sched" value="" required>
<span id="skidka"></span>
<script type="text/javascript">
$(document).ready(function() {
$('#category').change(function () {
var category = $(this).find(':selected').val();
$.ajax({
url:_base_url_+"admin/appointments/get_cat.php",
type: 'POST',
data: {category: category},
success: (function (data) {
$("#date_field").html(data);
})
});
});
});
get-cat.php
$query = "SELECT * FROM `appointments` WHERE `id` = '".($_POST['category'])."'";
$result = $mysqli->query($query);
$data = '';
foreach ($result as $value){
$data .= $value['date_sched'];
}
echo $data;
?>
For retrieving data using Ajax + jQuery, you should write the following code:
Create an HTML button with id="showData". Ajax script will execute on click this button.
backend-script.php
<?php
include("database.php");
$db=$conn;
// fetch query
function fetch_data(){
global $db;
$query="SELECT * from usertable ORDER BY id DESC";
$exec=mysqli_query($db, $query);
if(mysqli_num_rows($exec)>0){
$row= mysqli_fetch_all($exec, MYSQLI_ASSOC);
return $row;
}else{
return $row=[];
}
}
$fetchData= fetch_data();
show_data($fetchData);
function show_data($fetchData){
echo '<table border="1">
<tr>
<th>S.N</th>
<th>Full Name</th>
<th>Email Address</th>
<th>City</th>
<th>Country</th>
<th>Edit</th>
<th>Delete</th>
</tr>';
if(count($fetchData)>0){
$sn=1;
foreach($fetchData as $data){
echo "<tr>
<td>".$sn."</td>
<td>".$data['fullName']."</td>
<td>".$data['emailAddress']."</td>
<td>".$data['city']."</td>
<td>".$data['country']."</td>
<td><a href='crud-form.php?edit=".$data['id']."'>Edit</a></td>
<td><a href='crud-form.php?delete=".$data['id']."'>Delete</a></td>
</tr>";
$sn++;
}
}else{
echo "<tr>
<td colspan='7'>No Data Found</td>
</tr>";
}
echo "</table>";
}
?>
ajax-script.js
$(document).on('click','#showData',function(e){
$.ajax({
type: "GET",
url: "backend-script.php",
dataType: "html",
success: function(data){
$("#table-container").html(data);
}
});
});
You need to make it so that when your date changes, you fetch data based on that date:
<input type="date" class="form-control" name="date_sched" id='date_sched' required>
<script type='text/javascript'>
$(document).ready(function(){
$(document).on('change', '#date_sched', function(){
let date = $(this).val();
$.ajax({
url:_base_url_+"admin/appointments/get_cat.php",
type: 'POST',
data: {date: date},
success: function (data) {
$("#data_to_be_shown").html(data);
);
});
});
});
</script>
Your query then, should look something like this:
$date = $_POST['date'];
$sql = "SELECT * FROM `table_name` WHERE `date` = $date";
$stmt = $connection->query($sql);
Also I recommend you look up prepared statements.
Im not sure what you want, are you mean server side table with date filter?
If yes, I think this will help:
https://datatables.net/examples/data_sources/server_side
You can read the docs for advance costume date range filter or for your own filter

How do we pass data in ajax? [duplicate]

This question already has answers here:
How can I get the data-id attribute?
(16 answers)
Closed 5 years ago.
I am new to Ajax and I am confused as to how we pass data in Ajax. I have an index.php file which displays some data, it has a link to delete the record, now the problem is, I am not able to figure out how to transfer the id value from index.php of the selected record to ajax file. Also, how should I go about once I have fetched the value in delete.php page where lies the code to delete records.
I have coded as below.
index.php
<div id="delMsg"></div>
<?php
$con=mysqli_connect("localhost","root","","ajaxtest");
$data=mysqli_query($con,"select * from member");
$col=mysqli_num_fields($data);
echo "<table>";
while($row=mysqli_fetch_array($data))
{
echo "<tr>";
for($i=0;$i<$col;$i++)
{
echo "<td>".$row[$i]."</td>";
}
echo "<td><a class='del' href='delete.php' data-ID=$row[0]>Delete</a></td>";
echo"</tr>";
}
echo "</table>";
?>
ajax-file.js
$(document).ready(function(){
$(".del").click(function(event){
event.preventDefault();
$.ajax({
url:"delete.php",
method:"get",
data:{id:'ID'},
dataType:"html",
success:function(str){
$('#delMsg').html(str);
}
})
})
})
delete.php
<?php
$id=$_GET['id'];
$con=mysqli_connect("localhost","root","","ajaxtest");
$data=mysqli_query($con,"delete from member where id='$id'");
if($data)
{
echo "success";
}
else
{
echo "error";
}
?>
Hopefully this conveys the idea of how an AJAX call works.
The first thing we want to do is setup our trigger, which in your case is a button with an onclick event.
<script
src="http://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<!-- <button id="delete">Delete Something</button> -->
<button id="delete" onclick="onClickHandler(5)">Delete Something</button>
<p id="message">AJAX</p>
<script>
/* Notice I removed the document ready */
function onClickHandler(id)
{
event.preventDefault();
$.ajax(
{
url:"delete.php",
method:"POST", /* In the real world you want to use a delete here */
data: { /* plugin your data */
id: id,
name: "Bob",
age: 25
},
dataType:"html",
success: function(success) {
// Handle the success message here!
if (success) {
$('#message').text("Your message was received!");
}
},
error: function(error) {
// Handle your errors here
$('#message').text("Something went wrong!");
}
});
};
</script>
Notice how my data is prepared in the data object. I leave it up to you to figure out how to grab data and set it in the right field. You could: $('#someId').value(); or pass it through a function. If this is a source of confusion I can clarify.
data: { /* plugin your data */
id: 1,
name: "Bob",
age: 25
},
Next, we need to setup our script.
delete.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Obviously validate the data.
// But this is how you access it.
// $_POST is a global array, so you can access it like so:
$id = $_POST['id'];
$name = $_POST['name'];
$age = $_POST['age'];
// Do your server side stuff...
$sql = "DELETE FROM member
WHERE id = '{$id}' AND name = '{$name}' AND age = '{$age}'";
// Do your SQL (delete) here
// $con = mysqli_connect("localhost","root","","ajaxtest");
// Use prepared statements http://bobby-tables.com/php
// $data = mysqli_query($con,"delete from member where id='$id'");
// if ($data) { // Your condition
// This is where you would check if the query passed
// and send back the appropriate message.
if ($id) {
echo json_encode($id);
}
else {
echo http_response_code(500);
}
}
else {
echo "You don't belong here!";
}
you should use what is called JSON ( Javascript Object Notation, I think). This will let you order your data better to do that you have to use, json_encode.
Now I am not exactly sure what you mean by this id value from index.php
But taking your index.php file, I would change it like this
//make sure the is no space here
<?php
//start output buffering
ob_start();
$html = ['<div id="delMsg"></div>'];
$con=mysqli_connect("localhost","root","","ajaxtest");
$data=mysqli_query($con,"select * from member");
$col=mysqli_num_fields($data);
$html[] = "<table>";
while($row=mysqli_fetch_array($data))
{
$html[] = "<tr>";
for($i=0;$i<$col;$i++)
{
$html[] = "<td>".$row[$i]."</td>";
}
$html[] = "<td><a class='del' href='delete.php' data-ID=$row[0]>Delete</a></td>";
$html[] = "</tr>";
}
$html[] = "</table>";
$result = [
'html' => implode("\n", $html),
'debug' => ob_get_clean()
];
header("Content-type:application/json");
echo json_encode($result);
//?> ending tags are undesirable
Your JavaScript part will change too
$(document).ready(function(){
$(".del").click(function(event){
event.preventDefault();
$.ajax({
url:"delete.php",
method:"get",
data:{id:'ID'},
dataType:"html",
success:function(data){
$('#delMsg').html(data.html);
}
})
})
})
You can see now that instead of just returning HTML, We will be returning it like this data in the Javascript and $result in php
{
html : '<div id=" ...',
debug : ""
}
I added ob_start and ob_get_clean this can be helpful because you cannot just echo content when outputting JSON, so this will catch any echo or print_r type content and put that into the debug item in the return.
Just replace
echo "<td><a class='del' href='delete.php' data-ID=$row[0]>Delete</a></td>";
To
echo "<td><a onclick="deleteRow($row[0])">Delete</a></td>";
Javascript
function deleteRow(recordID)
{
event.preventDefault();
$.ajax({
type: "GET",
url: "delete.php",
data:{id: recordID}
}).done(function( result ) {
alert(result);
});
}
In your PHP I recommend you to use PDO which is more easy and protected from SQL injection attacks.
PHP:
$db = new PDO('mysql:host=localhost;dbname=yourDB','root','');
$query = $db->prepare("Delete From yourTableName Where ID=:ID");
$id=$_GET['id'];
$query->bindParam('ID', $id);
$query->execute();
if ($query->rowCount()) {
echo "success";
}
else
{
echo "fails";
}

While loop updation value

I am developing online attendance.But I stuck in while loop condition
I want to show my code first
<tbody>
<?php
$database = new Database();
$db = $database->getConnection();
$user = new User($db);
$stmt = $user->atten();
while($ro22 = $stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><input name ="uname" id ="uname" onBlur="checkAvailability2()" style ="border:none" value = "<?php echo $ro22['user_id'] ?>"/></td>
<td><?php echo $ro22['first_name'] ?> <?php echo $ro22['last_name'] ?></td>
<td><?php echo $ro22['parent_contact'] ?></td>
<td><input type="button" value="<?php echo $ro22['ai'] ?>" id="pres" name="pres" onclick="return change(this);" onBlur="checkAvailability()" class="w3-button w3-teal"/></td>
</tr>
<?php } ?>
</tbody>
This is output
What I want
I want update present,absent value based on 101,102,103... value
I tried many but failed. Please help me out
Thanks in advance
You need to place a call to the page on a click and pass the user_id. This is easy to do with jQuery:
function change(row) {
$.post('thispage.php', { user_id: $(row).val() }, function(){ window.location.reload(); } );
}
And then receive the post in the PHP:
if (!empty($_POST['user_id'])) {
/* toggle admission status */
}
After the request completes and the status is toggled, the page will reload.
Here is a general example. It's consisted of your PHP program (the AJAX sender) which I rewrote to be they way I think you wanted, a javascript file (containing the AJAX function) and another PHP file (the AJAX request receiver).
You can get different use-cases by altering the database query in the receiving PHP file.
Javascript file (AJAX):
// Send the `id` of the element
function checkAvailability(id)
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
// This `if` underneath is success. It means we got a response back
if (this.readyState == 4 && this.status == 200)
{
if(this.responseText == "OK")
{
alert('ID: ' + id + ' changed. Response: ' + this.responseText);
document.getElementById("demo").innerHTML = 'The student has been updated.';
}
else if(this.responseText == "Not OK")
{
alert('Something went wrong with id: ' + id);
}
}
};
// For example you send a request to attendance.php sending `id` info
// - attendance.php just needs to echo the response to answer back
xhttp.open("GET", "attendance.php?id=" + id, true);
xhttp.send();
}
Main PHP page (the file that sends the request):
// U need jQuery to be able to send AJAX requests. Copy this, add to your html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<?php
$database = new Database();
$db = $database->getConnection();
$user = new User($db);
$stmt = $user->atten();
echo '<table>
<tr>
<th>Student ID</th>
<th>Student name</th>
<th>Phone number</th>
<th>Today\'s attendance</th>
</tr>';
while($ro22 = $stmt->fetch(PDO::FETCH_ASSOC))
{
echo '<tr>
<td><input name ="uname" id ="uname" onBlur="checkAvailability2()" style ="border:none" value="'.$ro22['user_id'].'"/></td>
<td>'.$ro22['first_name'].' '.$ro22['last_name'].'</td>
<td>'.$ro22['parent_contact'].'</td>
<td><input type="button" value="'.$ro22['ai'].'" id="pres" name="pres" onclick="change(this.id);" onBlur="checkAvailability(this.id)" class="w3-button w3-teal"/></td>
</tr>';
}
echo '</table>';
?>
The receiver file:
<?php
$conToDatabase = ... // Here goes DB connection data
if(isset($_GET['id']) && ctype_digit($_GET['id']))
{
$clean['id'] = $_GET['id'];
}
// Query your DB here using variable $clean['id'] as ID
$querySuccess = ...
// if query successful echo 'OK';
// else echo 'Not OK';
?>

Using current lat/lng to query database and return data to user in php

So I have an issue where I want to be able to query some data with the user's current location but I am still new to JSON and trying to figure out how to send the data back to the main page.
Here are the hidden inputs for the lat/lng values on the index.php page
<input type="hidden" id="latitude">
<input type="hidden" id="longitude">
Here is the code to send the lat/lng to tables.php from the index.php page
$.getJSON(GEOCODING).done(function(location) {
$('#latitude').html(position.coords.latitude);
$('#longitude').html(position.coords.longitude);
$.ajax({
url:'table.php',
method: 'POST',
dataType: 'json',
data:{
lat: $('#latitude').val(),
lng: $('#longitude').val()
},
success: function(data){
console.log();
}
});
});
I am using datatables to display the data on the index.php page.
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.css">
<script>
$(document).ready(function(){
var dataTable = $('#searchTable').dataTable();
$("#searchbox").keyup(function() {
dataTable.fnFilter(this.value);
});
});
</script>
echo'<table id="searchTable" class="display">
<thead>
<tr>
<th>Latitude</th>
<th>Longitude</th>
</tr>
</thead>
<tbody>
';
(data to display from tables.php)
echo'</tbody>
</table>
';
And then on the tables.php page I am pulling the data from the MYSQL database, now this is where I have to figure out how to send the data back to the index.php page through JSON and display it in the table.
<?php
require_once("connect.php");
$lat = isset($_POST['lat']) ? $_POST['lat'] : null;
$lng = isset($_POST['lng']) ? $_POST['lng'] : null;
if($lat && $lng){
$locations = array();
$stmt = "SELECT * FROM location LIMIT 500"; //Query data from table
$stmt = $conn->prepare($stmt);
$stmt->execute();
if($stmt->rowCount() > 0){
$result = $stmt->fetchAll();
foreach($result as $row){
echo'<tr>
<td>';
$locations['Latitude'][] = $row;
echo'</td>
<td>';
$locations['Longitude'][] = $row;
echo'</td>
</tr>';
}
}
return json_encode($locations);
}
?>
What I am looking to do is update the table with data from the database based on the user's current location, when the user lands on the index.php page, Or the user can also search for a location using the search bar provided on the index.php page.
Thank you in advance for your time.
You need to first send JSON correctly from PHP file, and then receive at the AJAX response and parse to use it further to show in data tables. See below codes for the help.
Client side code:
$.getJSON(GEOCODING).done(function(location) {
$('#latitude').html(position.coords.latitude);
$('#longitude').html(position.coords.longitude);
$.ajax({
url:'table.php',
method: 'POST',
dataType: 'json',
data:{
lat: $('#latitude').val(),
lng: $('#longitude').val()
},
success: function(data){
// Here you need to parse the JSON data and put it in the data table rows by looping over it, see example code #E1
console.log();
}
});
});
PHP Code:
<?php require_once("connect.php"); $lat = isset($_POST['lat']) ? $_POST['lat'] : null; $lng = isset($_POST['lng']) ? $_POST['lng'] : null; if($lat && $lng){ $locations = array(); $stmt = "SELECT * FROM location LIMIT 500"; //Query data from table $stmt = $conn->prepare($stmt);$stmt->execute(); if($stmt->rowCount() > 0){ $result = $stmt->fetchAll(); foreach($result as $row){
$result[] = ['col1'=>$row['col1'],'col2'=>$row['col2']]; // here you need to add as many columns as you want to show in the data table } } print json_encode($result);die; } ?>
Example codes:-
_#E1_
console.log(JSON.stringify(json.topics)); $.each(json.topics, function(idx, topic){ $("#nav").html('' + topic.link_text + ""); });
Apply code as per your need and it will resolve your problem. Assuming you are getting proper data from the database query.
Hope it helps.
Thanks

Inserting data into mysql using jquery yes or no vote

How can i update the database by adding users choices? I have two fields in the database for this purpose, when the user click on yes, it updates the (useful) field and (not_useful) if clicked on no button. I am very new on javascript, so please be patient! :) I appreciate any help in advance.
PHP
<?php
require 'db/conn.php':
$id = (int)$_GET['id'];
if($result = $db->query("SELECT * FROM table_user WHERE table_user_id = $id")){
if($result->num_rows){
while($row = $result->fetch_assoc()) {
echo "
<div class='rating'>
<center>
<p>Are you alrite " . $row['table_user_name'] . "?</p>
<div>
<button type='button' id='yes'>Yes</button>
<button type='button' id='no'>No</button>
</div>
</center>
</div>
<div class='1' style='display:none;'>Text YES</div>
<div class='2' style='display:none;'>Text NO</div>
";
}
}
}
?>
JS
$(document).ready(function(){
$("#yes").click(function(){
$(".rating").hide();
$(".1").show();
});
$("#no").click(function(){
$(".rating").hide();
$(".2").show();
});
});
You can't connect your mySQL database directly with JavaScript from client browser. Event if it would be possible you really don't want to do that because you would have to include mysql login credentials into your JavaScript which is served to client computers.
Of course you could use database like LocalStorage from within JavaScript but these databases are on client computer. If I got it right thats not what you are looking.
You have to send the data to a script on your server which then insert them into your mySQL database. As you stated you don't like the browser to reload to just submitting a form is not an option. In these cases AJAX is used. You will find several tutorials how to send data with JavaScript / JQuery using AJAX to your server.
On server side you could handle for example with a php script. The code you have posted to your question is not PHP but simple HTML. Fred -ii- posted some sample SQL statements to increment a column. I would recommend you to use PHP PDO with mysql driver as this helps you to prevent security issues.
After some working hard, i found a solution. Sharing for those who is facing similar problem. This was my solution. Anyways, have fun! ;)
I think there's a better way to organize the JS script to interact with the php files which manage the sql scripts. If someone would like to help optimize it, will be welcome.
PHP main
<?php
require 'db/conn.php':
$id = (int)$_GET['id'];
if($result = $db->query("SELECT * FROM table WHERE user_id = $id")){
if($result->num_rows){
while($row = $result->fetch_assoc()) {
echo "
<div class='rating'>
<center>
<p>Are you alrite " . $row['user_name'] . "?</p>
<div id='rating-div'>
<a href='#' id='yes' class='custom-btn'>Yes</a>
<a href='#' id='no' class='custom-btn'>No</a>
<input type='hidden' id='" . $id . "' />
</div>
</center>
</div>
";
}
}
}
?>
JS
$(function(){
$('#yes').on('click', function(e){
e.preventDefault();
var usr_id = $('#rating-div input').attr('id');
$.ajax({
url: 'db/rating-yes.php',
type: 'post',
data: {'action': 'rating', 'usr_id': user_id},
success: function(data, status){
if(data == "ok"){
$('.rating').html('<p>Nice!</p>');
}//end of if
},//end of success function
error: function(xhr, desc, err){
console.log(xhr);
console.log("Details: " + desc + "\nError: "+ err);
}
});//end of ajax
}); //end of onclick function
}); //end of main function
$(function(){
$('#no').on('click', function(e){
e.preventDefault();
var usr_id = $('#rating-div input').attr('id');
$.ajax({
url: 'db/rating-no.php',
type: 'post',
data: {'action': 'rating', 'usr_id': user_id},
success: function(data, status){
if(data == "ok"){
$('.rating').html('<p>Oh no! :(</p>');
}//end of if
},//end of success function
error: function(xhr, desc, err){
console.log(xhr);
console.log("Details: " + desc + "\nError: "+ err);
}
});//end of ajax
}); //end of onclick function
}); //end of main function
PHP rating-yes
<?php
$rating = $_POST['action'];
$user_id = $_POST['usr_id'];
if($rating == "rating") {
$conn = mysql_connect('localhost', 'root', '');
$db = mysql_select_db('your_database');
if(mysql_query("UPDATE table SET useful = useful + 1 WHERE user_id = $user_id")){
echo "ok";
}
}
?>
PHP rating-no
<?php
$rating = $_POST['action'];
$user_id = $_POST['usr_id'];
if($rating == "rating") {
$conn = mysql_connect('localhost', 'root', '');
$db = mysql_select_db('your_database');
if(mysql_query("UPDATE table SET not_useful = not_useful + 1 WHERE user_id = $user_id")){
echo "ok";
}
}
?>

Categories