473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

On refresh web page updated content will set to 0

ak1dnar
1,584 Expert 1GB
Hi,

I am developing a web site that displays Products, and along with each products there is a Button.There is a <DIV> in my page to display Number of Products Added to the Basket.
Items : 0

When user comes to the page, items will display as 0. if click the Button along with the product items will set to 1. Again user can click product only one time.
Like wise for each and every onclick my Ajax function will fire.
This is how it works:
onclick button Product items will add to MySQL table with session ID
By Calculating Num of Product ID s I will Update it in the DIV.

Again for the for body onload also i am doing the same.for that i will call for onload() function in ajax script. is there any problem in my coding

These things already completed. But there is bug in my application.When i refresh my page all the Added items will set to 0 again.I need to prevent this.
Please help on this.

Do not check the AJAX part just check my PHP code because this is PHP forum But if you can help on that its highly appreciate.


ajax.js
Expand|Select|Wrap|Line Numbers
  1. var xmlHttp
  2. var xmlHttp1
  3. function get_id(p_id)
  4. {
  5. xmlHttp=GetXmlHttpObject()
  6. if (xmlHttp==null)
  7.  {
  8.  alert ("Your Browser is too old please Update It....")
  9.  return
  10.  } 
  11. var url="tocart.php"
  12. url=url+"?pid="+p_id
  13. //url=url+"&amp;sid="+Math.random()
  14. xmlHttp.onreadystatechange=stateChanged 
  15. xmlHttp.open("GET",url,true)
  16. xmlHttp.send(null)
  17. }
  18. function onload(sid)
  19. {
  20. xmlHttp=GetXmlHttpObject()
  21. if (xmlHttp==null)
  22.  {
  23.  alert ("Your Browser is too old please Update It....")
  24.  return
  25.  } 
  26. var url="onload.php?sid="+sid
  27. xmlHttp.onreadystatechange=stateChanged2
  28. xmlHttp.open("GET",url,true)
  29. xmlHttp.send(null)
  30.  
  31. function stateChanged() 
  32. if (xmlHttp.readyState==4)
  33. xmlDoc=xmlHttp.responseXML;
  34. document.getElementById("sid").innerHTML=xmlDoc.getElementsByTagName("sid")[0].childNodes[0].nodeValue;
  35. function stateChanged2() 
  36. if (xmlHttp.readyState==4)
  37.  
  38. document.getElementById("sid").innerHTML=xmlHttp.responseText;
  39. function GetXmlHttpObject()
  40. var objXMLHttp=null
  41. if (window.XMLHttpRequest)
  42.  {
  43.  objXMLHttp=new XMLHttpRequest()
  44.  }
  45. else if (window.ActiveXObject)
  46.  {
  47.  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  48.  }
  49. return objXMLHttp
  50. }
tocart.php
[PHP]<?php
header('Content-Type: text/xml');
//header("Cache-Control: no-cache, must-revalidate");
$pid = $_REQUEST['pid'];
session_start();
$sid=session_id();
require 'dbcon.php';

$chksql = "SELECT p_id FROM cart where ct_session_id= '$sid' AND p_id = '$pid'";
$chkresult=mysql_query($chksql);
if(mysql_num_rows($chkresult) == 0)
{
$sql="INSERT INTO cart (p_id, ct_qty, ct_session_id, ct_date)
VALUES ($pid , 1, '$sid', NOW())";
if (!mysql_query($sql,$con))
{
$sql_count = "SELECT count( p_id ) AS counters FROM `cart`
WHERE ct_session_id = '$sid'";
$result=mysql_query($sql_count);
$row = mysql_fetch_array($result);
$msg = $row['counters'];
}
else
{
$sql_count = "SELECT count( p_id ) AS counters FROM `cart`
WHERE ct_session_id = '$sid'";
$result=mysql_query($sql_count);
$row = mysql_fetch_array($result);
$msg = $row['counters'];
}
}
else
{
$sql_count = "SELECT count( p_id ) AS counters FROM `cart`
WHERE ct_session_id = '$sid'";
$result=mysql_query($sql_count);
$row = mysql_fetch_array($result);
$msg = $row['counters'];
}

echo '<?xml version="1.0" encoding="ISO-8859-1" ?><products>';
echo '<sid>'.$msg. '</sid>';
echo "</products>";
mysql_close($con);
?>[/PHP]

onload.php

[PHP]<?php
$sid = $_REQUEST['sid'];
require 'dbcon.php';
$sql_count = "SELECT count( p_id ) AS counters FROM `cart`
WHERE ct_session_id = '$sid'";
$result=mysql_query($sql_count);
$row = mysql_fetch_array($result);
$msg = $row['counters'];
if($msg==0){
echo "0";
}
else{
echo $msg;
}
mysql_close($con);
?>[/PHP]
Mar 7 '07 #1
0 1459

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bite My Bubbles | last post by:
I found the answer! It is a IIS 6 /ASP problem http://support.microsoft.com/default.aspx?scid=kb;en-us;332075
1
by: SPQR | last post by:
Some time ago I set up a webcam at home and a page on my site. Every three minutes the webcam would take a picture of my backyard and ftp it to my site where it was displayed on my webcam page. ...
3
by: Will Appleby | last post by:
I'm trying to create a web page that will refresh each time someone visits so they always see an updated version. I've tried using <META HTTP-EQUIV="refresh" CONTENT=";URL=index.html"> in the...
1
by: Marco Maroni | last post by:
How to force image refresh on client browser ? Is ti possible to force the refresh of the same image (tha was changed server-side) to the client, without user press Contrl+F5 in IE ? - Marco
2
by: joeblast | last post by:
HI, Can someone explain to me why the <meta http-equiv="refresh" content="5"/> will not work for me? I use it in a standard asp page and it works just fine. Why in ASP.NET2.0 it doesn't. I...
11
by: Jerry J | last post by:
How can I get an asp:Image to refresh when a user uploads a different jpg. I disabled caching using this command on Page_Load(): Response.Cache.SetCacheability(HttpCacheability.No Cache); but it...
6
ak1dnar
by: ak1dnar | last post by:
Hi, I am developing a web site that displays Products, and along with each products there is a Button.There is a <DIV> in my page to display Number of Products Added to the Basket. Items : 0 ...
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
4
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.