ballouta Posted November 17, 2008 Share Posted November 17, 2008 Hi, I have a cart.php page. I used a popup windows when the member wants to update an item qty or if the member wants to empty his cart. This popup windows is working properly and i have no problem, BUT after updating the qty or deleting an item or emptying the cart, how do i make the cart.php page refreshed automatically? can this be done? Note that after changing the qty, a query runs and i echo a script to close this popup window automatically. after that i want to refresh the cart.. `thank you Link to comment https://forums.phpfreaks.com/topic/133119-refresh/ Share on other sites More sharing options...
webster08 Posted November 18, 2008 Share Posted November 18, 2008 reload the cart.php with a function from within your pop-up; aka "javascript pop-up remote control". Link to comment https://forums.phpfreaks.com/topic/133119-refresh/#findComment-692577 Share on other sites More sharing options...
BoltZ Posted November 18, 2008 Share Posted November 18, 2008 do like <?php if (isset($query)) Header("Location: http://www.yoursite.com/cart.php"); ?> Or match that to your needs Link to comment https://forums.phpfreaks.com/topic/133119-refresh/#findComment-692640 Share on other sites More sharing options...
ballouta Posted November 18, 2008 Author Share Posted November 18, 2008 Hi i pasted these lines at the end of the deletion code but it didn't work why? <?php $query = "DELETE from `orders` WHERE `orderno` = '$order' AND `member` = '$user'"; $result = mysql_query($query); //change the order status to C ==> canceled $query = "update `ordersmaster` SET `status` = 'C' WHERE `orderno` = '$order' AND `member` = '$user'"; $result = mysql_query($query); if (isset($query)) Header("Location: http://www.dmcpublisher.com/shopping/cart.php"); ?> Link to comment https://forums.phpfreaks.com/topic/133119-refresh/#findComment-692677 Share on other sites More sharing options...
FireDrake Posted November 18, 2008 Share Posted November 18, 2008 Hi i pasted these lines at the end of the deletion code but it didn't work why? <?php $query = "DELETE from `orders` WHERE `orderno` = '$order' AND `member` = '$user'"; $result = mysql_query($query); //change the order status to C ==> canceled $query = "update `ordersmaster` SET `status` = 'C' WHERE `orderno` = '$order' AND `member` = '$user'"; $result = mysql_query($query); if (isset($query)) Header("Location: http://www.dmcpublisher.com/shopping/cart.php"); ?> What didn't work? What is the error? Also, you should make your PHP parts in queries like this: $query = "update `ordersmaster` SET `status` = 'C' WHERE `orderno` = ".$order." AND `member` = ".$user; If the error was "headers already send", add 'ob_start()' at the top of your page and 'ob_end_flush()' at the bottom. 'Header' should be without capital.. Link to comment https://forums.phpfreaks.com/topic/133119-refresh/#findComment-692681 Share on other sites More sharing options...
ballouta Posted November 18, 2008 Author Share Posted November 18, 2008 Hi, I fixed the PHP query parts. I didn't get any error, but after those php lines run, nothing happens in the cart.php page. Link to comment https://forums.phpfreaks.com/topic/133119-refresh/#findComment-692695 Share on other sites More sharing options...
BoltZ Posted November 18, 2008 Share Posted November 18, 2008 Are you opening a connection to the database? I don't see it Link to comment https://forums.phpfreaks.com/topic/133119-refresh/#findComment-692894 Share on other sites More sharing options...
perezf Posted November 19, 2008 Share Posted November 19, 2008 i need to see more of your code, for instance how are you handling the popup You need to make a javascript event based on that. Link to comment https://forums.phpfreaks.com/topic/133119-refresh/#findComment-693178 Share on other sites More sharing options...
ballouta Posted November 19, 2008 Author Share Posted November 19, 2008 Hi I will display all my code, the cart.php contains this script in its header <script language="javascript" type="text/javascript"> <!-- /**************************************************** Author: Eric King Url: http://redrival.com/eak/index.shtml This script is free to use as long as this info is left in Featured on Dynamic Drive script library (http://www.dynamicdrive.com) ****************************************************/ var win=null; function NewWindow(mypage,myname,w,h,scroll,pos){ if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;} if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;} else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20} settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no'; win=window.open(mypage,myname,settings);} // --> </script> There's an edit symbol the user presses on it to view the popup: <a href=\"http://www.dmcpublisher.com/shopping/edit~qty.php?id=$row[book]\" onclick=\"NewWindow(this.href,'mywin','200','180','no','center');return false\" onfocus=\"this.blur()\"> <img border='0' src='../images/edit.JPG' width='18' height='18' alt='Edit QTY'></a> This popup code is: <?php $user = $_SESSION['authen']; $order = $_SESSION['thisorder']; include('../CMS/operations.inc.php'); echo "<p align='center'><font face='Tahoma'><span style='font-size: 10pt'>Are you sure u want to empty ur cart</span></font></p> <p align='center'><font face='Tahoma' size='2'><font color='#FF0000'> <a href='empty~cart~save.php?id=$id'><font color='#FF0000'>yes</font></a></font> <font color='#008000'><font color='#008000'><a href=\"javascript:window.close();\">NOfont></a></font></font></p>"; ?> and the code where it updates the qty is: <?php $user = $_SESSION['authen']; $order = $_SESSION['thisorder']; include('../CMS/operations.inc.php'); mysql_query("SET CHARACTER_SET_RESULTS=NULL"); $query = "DELETE from `orders` WHERE `orderno` = '$order' AND `member` = '$user'"; $result = mysql_query($query); //change the order status to C ==> canceled $query = "update `ordersmaster` SET `status` = 'C' WHERE `orderno` = '$order' AND `member` = '$user' "; $result = mysql_query($query); if (isset($query)) Header("Location: http://www.dmcpublisher.com/shopping/cart.php"); echo " <SCRIPT LANGUAGE=\"JavaScript\"> <!--hide window.close(); //--> </SCRIPT> "; ?> Thank you Link to comment https://forums.phpfreaks.com/topic/133119-refresh/#findComment-693333 Share on other sites More sharing options...
FireDrake Posted November 19, 2008 Share Posted November 19, 2008 I'll give the code some structure first.. JavaScript in header: <script language="javascript" type="text/javascript"> <!-- /**************************************************** Author: Eric King Url: http://redrival.com/eak/index.shtml This script is free to use as long as this info is left in Featured on Dynamic Drive script library (http://www.dynamicdrive.com) ****************************************************/ var win=null; function NewWindow(mypage,myname,w,h,scroll,pos){ if(pos=="random"){ LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100; TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100; } if(pos=="center"){ LeftPosition=(screen.width)?(screen.width-w)/2:100; TopPosition=(screen.height)?(screen.height-h)/2:100; } else if((pos!="center" && pos!="random") || pos==null){ LeftPosition=0; TopPosition=20; } settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no'; win=window.open(mypage,myname,settings); } // --> </script> Popup button: <?php echo " <a href=\"http://www.dmcpublisher.com/shopping/edit~qty.php?id=".$row[book]."\" onclick=\"NewWindow(this.href,'mywin','200','180','no','center'); return false\" onfocus=\"this.blur()\"> <img border='0' src='../images/edit.JPG' width='18' height='18' alt='Edit QTY'> </a>" ?> This popup code: <?php session_start(); $user = $_SESSION['authen']; $order = $_SESSION['thisorder']; include('../CMS/operations.inc.php'); //Never use the <font> tags... echo "<p align='center'> <font face='Tahoma'> <span style='font-size: 10pt'>Are you sure you want to empty your cart?</span> </font> </p> <p align='center'> <font face='Tahoma' size='2'> <font color='#FF0000'> <a href='empty~cart~save.php?id=$id'> <font color='#FF0000'>yes</font> </a> </font> <font color='#008000'> <font color='#008000'> <a href=\"javascript:window.close();\">NO</a> </font> </font> </font> </p>"; ?> Code where it updates the qty: <?php session_start(); $user = $_SESSION['authen']; $order = $_SESSION['thisorder']; include('../CMS/operations.inc.php'); mysql_query("SET CHARACTER_SET_RESULTS=NULL"); $query = "DELETE from `orders` WHERE `orderno` = ".$order." AND `member` = ".$user; $result = mysql_query($query); //change the order status to C ==> canceled $query = "update `ordersmaster` SET `status` = 'C' WHERE `orderno` = ".$order." AND `member` = ".$user; $result = mysql_query($query); if (isset($query)) header("Location: http://www.dmcpublisher.com/shopping/cart.php"); echo "<SCRIPT LANGUAGE=\"JavaScript\"> <!--hide window.close(); //--> </SCRIPT> "; ?> I added session_start(); where it updates the qty, and at the popup (don't know if it was anywhere else) Also, add an exit(); before the header, so you can see what the error is. example: <?php session_start(); $user = $_SESSION['authen']; $order = $_SESSION['thisorder']; include('../CMS/operations.inc.php'); mysql_query("SET CHARACTER_SET_RESULTS=NULL"); $query = "DELETE from `orders` WHERE `orderno` = ".$order." AND `member` = ".$user; $result = mysql_query($query); //change the order status to C ==> canceled $query = "update `ordersmaster` SET `status` = 'C' WHERE `orderno` = ".$order." AND `member` = ".$user; $result = mysql_query($query); //add exit, so the script won't continue, and you can see what the error is exit(); if (isset($query)) header("Location: http://www.dmcpublisher.com/shopping/cart.php"); echo "<SCRIPT LANGUAGE=\"JavaScript\"> <!--hide window.close(); //--> </SCRIPT> "; ?> You can also add: <?php echo $user."<br />"; echo $order; ?> To see if they are not empty.. Link to comment https://forums.phpfreaks.com/topic/133119-refresh/#findComment-693364 Share on other sites More sharing options...
ballouta Posted November 19, 2008 Author Share Posted November 19, 2008 Hi, thanks for help Note that i have the line that starts session but i didn't show it to you by mistake. anyway, i echoed before all variables and session values they are correct. I just run the code you gave me, after press Yes on empty_cart, teh popup windows didn't close automatically and was all white and empty. and the cart.php didn't not make refresh:( Link to comment https://forums.phpfreaks.com/topic/133119-refresh/#findComment-693608 Share on other sites More sharing options...
FireDrake Posted November 20, 2008 Share Posted November 20, 2008 Did the database update? I think you can better use AJAX to reach what you try to do. add to the JavaScript part: function GetXmlHttpObject( handler ) { var objXmlHttp = null; if (navigator.userAgent.indexOf("Opera") >= 0) { alert ("Opera wordt niet ondersteund. Gebruik Firefox."); return; } if (navigator.userAgent.indexOf("MSIE") >= 0) { var strName = "Msxml2.XMLHTTP" if (navigator.appVersion.indexOf("MSIE 5.5") >= 0) { strName = "Microsoft.XMLHTTP"; } try { objXmlHttp = new ActiveXObject(strName) objXmlHttp.onreadystatechange = handler; return objXmlHttp; } catch(e) { alert("Error. Scripting for ActiveX might be disabled"); return; } } if (navigator.userAgent.indexOf("Mozilla") >= 0 ) { objXmlHttp = new XMLHttpRequest(); objXmlHttp.onload = handler; objXmlHttp.onerror = handler; return objXmlHttp; } } function UpdateCart(page, id, user, order) { url = page + "?rnd=" + Math.random() + "&id=" + id + "&update=1&user=" + user + "&order=" + order; xmlHttp = GetXmlHttpObject( CartUpdated ); xmlHttp.open("GET", url , true); xmlHttp.send( null ); } function CartUpdated() { if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") { if ( xmlHttp.status == 200 ) { document.getElementById('UpdateSpan').innerHTML = xmlHttp.responseText; } else alert ( xmlHttp.statusText ); } } function ConfirmUpdate(page, id, user, order){ var message = confirm('Are you sure you want to empty your cart?'); if (message){ UpdateCart(page, id, user, order); } else { alert('Ok, nothing will happen, calm down!'); } } This way (with confirmation popup window) wil probably not work, but it's worth the try.. Button: <?php echo " <a href=\"http://www.dmcpublisher.com/shopping/edit~qty.php?id=".$row[book]."\" onclick=\"NewWindow(this.href,'mywin','200','180','no','center'); return false\" onfocus=\"this.blur()\"> <img border='0' src='../images/edit.JPG' width='18' height='18' alt='Edit QTY'> </a><span id=\"UpdateSpan\"> </span>" ?> Popup window: <?php session_start(); $user = $_SESSION['authen']; $order = $_SESSION['thisorder']; $id = $_GET['id'] include('../CMS/operations.inc.php'); //Never use the <font> tags... echo "<p align='center'> <font face='Tahoma'> <span style='font-size: 10pt'>Are you sure you want to empty your cart?</span> </font> </p> <p align='center'> <font face='Tahoma' size='2'> <font color='#FF0000'> <a href='#' onclick=\"UpdateCart('empty~cart~save.php', '".$id."', '".$user."', '".$order."')\"> <font color='#FF0000'>yes</font> </a> </font> <font color='#008000'> <font color='#008000'> <a href=\"javascript:window.close();\">NO</a> </font> </font> </font> </p>"; ?> In the Popup where it updates the cart in the database (the Ajax part links to that page): <?php if (isset($_GET['update']){ $user = $_GET['user']; $order = $_SESSION['order']; include('../CMS/operations.inc.php'); mysql_query("SET CHARACTER_SET_RESULTS=NULL"); $query = "DELETE from `orders` WHERE `orderno` = ".$order." AND `member` = ".$user; $result = mysql_query($query); //change the order status to C ==> canceled $query = "update `ordersmaster` SET `status` = 'C' WHERE `orderno` = ".$order." AND `member` = ".$user; $result = mysql_query($query); echo '<meta http-equiv="refresh" content="0">'; } ?> _________________________ OR: Button: <?php session_start(); $user = $_SESSION['authen']; $order = $_SESSION['thisorder']; $id = $row[book]; echo " <a href='#' onclick=\"ConfirmUpdate('empty~cart~save.php', '".$id."', '".$user."', '".$order."')\" onfocus=\"this.blur()\"> <img border='0' src='../images/edit.JPG' width='18' height='18' alt='Edit QTY'> </a><span id=\"UpdateSpan\"> </span>" ?> No Popup window.. none Place where it updates the cart in the database (the Ajax part links to that page): <?php if (isset($_GET['update']){ $user = $_GET['user']; $order = $_GET['order']; include('../CMS/operations.inc.php'); mysql_query("SET CHARACTER_SET_RESULTS=NULL"); $query = "DELETE from `orders` WHERE `orderno` = ".$order." AND `member` = ".$user; $result = mysql_query($query); //change the order status to C ==> canceled $query = "update `ordersmaster` SET `status` = 'C' WHERE `orderno` = ".$order." AND `member` = ".$user; $result = mysql_query($query); echo '<meta http-equiv="refresh" content="0">'; } ?> It might be buggy (changed everything without trying), but if you read the code, and know how it works, I'm sure you can make it work. Link to comment https://forums.phpfreaks.com/topic/133119-refresh/#findComment-694226 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.