MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 18th, 2003, 03:12 AM
digital102 digital102 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 digital102 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Building A Persistent Shopping Cart With PHP and MySQL

I am getting an error with a shopping cart script.

The line that is causing the error is:

$query = "SELECT * FROM cart INNER JOIN products ON cart.itemId = products.id WHERE cart.cookieId = '" . GetCartId() . "' ORDER BY products.title ASC";

and the error I am getting is:

Warning: Supplied argument is not a valid MySQL result resource in /home/guitarc/public_html/cart.php on line 265

If anyone can offer any assistance that would be awesome!!!

Thanks in advance.

Reply With Quote
  #2  
Old April 18th, 2003, 05:20 AM
deedee deedee is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 11 deedee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to deedee
Can you tell us the output of GetCartId() ?

deedee

Reply With Quote
  #3  
Old April 18th, 2003, 06:11 AM
digital102 digital102 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 digital102 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
GetCartId()

This is the function that GetCartId() performs:

function GetCartId()
{
// This function will generate an encrypted string and
// will set it as a cookie using set_cookie. This will
// also be used as the cookieId field in the cart table
if(isset($_COOKIE["cartId"]))
{
return $_COOKIE["cartId"];
}
else
{
// There is no cookie set. We will set the cookie
// and return the value of the users session ID

session_start();
setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}

Let me know if you need more info!!
Thanks.

Reply With Quote
  #4  
Old April 18th, 2003, 06:16 AM
deedee deedee is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 11 deedee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to deedee
Well maybe we can clarify if you make an echo $query in order to see the output.

The function looks fine (will work on PHP ver 4.2.x or higher)

deedee

Reply With Quote
  #5  
Old April 18th, 2003, 06:28 AM
digital102 digital102 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 digital102 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
query result

This is the result I got when I made an echo $query:

SELECT * FROM cart INNER JOIN products ON cart.itemId = products.id WHERE cart.cookieId = 'c8df510bf89a65218316e8ec33187d48' ORDER BY products.title ASC

Thanks!!

Reply With Quote
  #6  
Old April 18th, 2003, 06:44 AM
digital102 digital102 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 digital102 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
New Info

I took a look at my database and it looks like this:

SELECT * FROM cart INNER JOIN products ON cart.itemId = products.id WHERE cart.cookieId = '" . GetCartId() . "' ORDER BY products.title ASC

is being done. So maybe my problem is with the code that is below that. This is what I have below that:

$result = mysql_query($query);

while($row = mysql_fetch_array($result))
{

Could the problem be here?

Any help you can offer is great!!!

Thanks in advance.

Reply With Quote
  #7  
Old April 18th, 2003, 06:47 AM
digital102 digital102 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 digital102 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
More additional info...

The error that I am getting on the browser is:

Warning: Supplied argument is not a valid MySQL result resource in /home/guitarc/public_html/cart.php on line 266


And on line 266 I have this:

while($row = mysql_fetch_array($result))

Do you think this is the actual problem and not my original query?

Thank again.

Reply With Quote
  #8  
Old April 18th, 2003, 07:08 AM
deedee deedee is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 11 deedee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to deedee
This should work:
/* REPLACE YOUR SERVER SETTINGS HERE */
mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("mydb");

$query="SELECT * FROM cart INNER JOIN products ON cart.itemId = products.id WHERE cart.cookieId = \"" . GetCartId() . "\" ORDER BY products.title ASC";

$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
// RESULTS HERE....

}

Also, you may check the database fields. I mean you must check if the JOIN in correct.

Reply With Quote
  #9  
Old April 18th, 2003, 07:16 AM
digital102 digital102 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 digital102 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Still having problems

I went ahead and made the changes you suggested, and I am still having the same problem. I checked my database and the INNER JOIN is happening correctly. So I know that the query is occuring and it is occurring correctly. I think the problem is with the way I am trying to obtain the results from the query.

There may be something wrong with the while loop.

What do you think?

Thanks again.

Reply With Quote
  #10  
Old April 18th, 2003, 07:32 AM
deedee deedee is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 11 deedee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to deedee
Can you paste the entire script? (without real login info of course)

Reply With Quote
  #11  
Old April 18th, 2003, 07:36 AM
digital102 digital102 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 digital102 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Here is the first half, too big to post as one

PHP Code:
<?php 

include("db.php"); 

switch(
$_GET["action"]) 

case 
"add_item"

AddItem($_GET["id"], $_GET["qty"]); 
ShowCart(); 
break; 

case 
"update_item"

UpdateItem($_GET["id"], $_GET["qty"]); 
ShowCart(); 
break; 

case 
"remove_item"

RemoveItem($_GET["id"]); 
ShowCart(); 
break; 

default: 

ShowCart(); 


function 
AddItem($itemId$qty

// Will check whether or not this item 
// already exists in the cart table. 
// If it does, the UpdateItem function 
// will be called instead 

global $dbServer$dbUser$dbPass$dbName

// Get a connection to the database 
$cxn = @ConnectToDb($dbServer$dbUser$dbPass$dbName); 

// Check if this item already exists in the users cart table
$query "select count(*) from cart where cookieId = '" GetCartId() . "' and itemId = $itemId";
$result mysql_query($query) or die("Couldn't execute query");
$row mysql_fetch_row($result);
$numRows $row[0];

if(
$numRows == 0

// This item doesn't exist in the users cart, 
// we will add it with an insert query 

@mysql_query("insert into cart(cookieId, itemId, qty) values('" GetCartId() . "', $itemId, $qty)"); 

else 

// This item already exists in the users cart, 
// we will update it instead 

UpdateItem($itemId$qty); 



function 
UpdateItem($itemId$qty

// Updates the quantity of an item in the users cart. 
// If the qutnaity is zero, then RemoveItem will be 
// called instead 

global $dbServer$dbUser$dbPass$dbName

// Get a connection to the database 
$cxn = @ConnectToDb($dbServer$dbUser$dbPass$dbName); 

if(
$qty == 0

// Remove the item from the users cart 
RemoveItem($itemId); 

else 

mysql_query("update cart set qty = $qty where cookieId = '" GetCartId() . "' and itemId = $itemId"); 



function 
RemoveItem($itemId

// Uses an SQL delete statement to remove an item from 
// the users cart 

global $dbServer$dbUser$dbPass$dbName

// Get a connection to the database 
$cxn = @ConnectToDb($dbServer$dbUser$dbPass$dbName); 

mysql_query("delete from cart where cookieId = '" GetCartId() . "' and itemId = $itemId"); 


function 
ShowCart()
{
// Gets each item from the cart table and display them in 
// a tabulated format, as well as a final total for the cart 

global $dbServer$dbUser$dbPass$dbName

// Get a connection to the database 
$cxn = @ConnectToDb($dbServer$dbUser$dbPass$dbName); 

$totalCost 0
$query "SELECT * FROM cart INNER JOIN products ON cart.itemId = products.id WHERE cart.cookieId = '" GetCartId() . "' ORDER BY products.title ASC";
$result mysql_query($query);
print(
$query);
?>

Reply With Quote
  #12  
Old April 18th, 2003, 07:37 AM
digital102 digital102 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 digital102 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Here is the second half, there is still one more to go.

Code:
<html>
<head>
<title>Guitar City</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript"> 

function UpdateQty(item) 
{ 
itemId = item.name; 
newQty = item.options[item.selectedIndex].text; 

document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty; 
} 

</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}
//-->
</script>
<link href="styles.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
a {
	color: #4F4F4F;
}
-->
</style>
<style type="text/css">
<!--
-->
</style>
</head>

<body bgcolor="#000000" leftmargin="0" topmargin="0" rightmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('images/home/products_on.gif','images/home/order_on.gif','images/home/contact_on.gif','images/home/links_on.gif','images/home/celebrity_on.gif','images/home/home_on.gif')">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td background="images/home/toptile.gif"><img src="images/home/toptile_left.gif" width="7" height="30"></td>
  </tr>
  <tr> 
    <td background="images/home/logo_tile.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td><img src="images/home/logo.gif" width="215" height="68"></td>
          <td align="right" valign="top"> <form name="form1" method="post" action="">
              <img src="images/home/choose_product.gif" width="125" height="22"> 
              <select name="menu" onChange="MM_jumpMenu('parent',this,0)">
                <option>Choose One</option>
                <option value="products.php?cat=electric">Electric Guitars</option>
                <option value="products.php?cat=acoustic">Acoustic Guitars</option>
                <option value="products.php?cat=bass">Bass Guitars</option>
                <option value="products.php?cat=classical">Classical Guitars</option>
                <option value="products.php?cat=vintage">Vintage Guitars</option>
                <option value="products.php?cat=other_stringed">Other Stringed 
                Instruments</option>
                <option value="products.php?cat=amplifiers">Amplifiers</option>
                <option value="products.php?cat=cases">Cases</option>
                <option value="products.php?cat=accessories">Strings and Accessories</option>
                <option value="products.php?cat=lefthanded">Left-Handed Guitars</option>
              </select>
              <input type="button" name="Button1" value="Go" onClick="MM_jumpMenuGo('menu2','parent',0)">
              &nbsp;&nbsp; </form></td>
        </tr>
      </table></td>
  </tr>
  <tr> 
    <td background="images/home/button_tile.gif"><table border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td width="78"><a href="categories.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image4','','images/home/products_on.gif',1)"><img src="images/home/products_off.gif" name="Image4" width="78" height="20" border="0"></a></td>
          <td width="88"><a href="https://earth.he.net/~guitarc/confirm_order.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image5','','images/home/order_on.gif',1)"><img src="images/home/order_off.gif" name="Image5" width="88" height="20" border="0"></a></td>
          <td width="88"><a href="contact.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image6','','images/home/contact_on.gif',1)"><img src="images/home/contact_off.gif" name="Image6" width="88" height="20" border="0"></a></td>
          <td width="58"><a href="links.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image7','','images/home/links_on.gif',1)"><img src="images/home/links_off.gif" name="Image7" width="58" height="20" border="0"></a></td>
          <td width="115"><a href="celebrity.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image8','','images/home/celebrity_on.gif',1)"><img src="images/home/celebrity_off.gif" name="Image8" width="115" height="20" border="0"></a></td>
          <td width="59"><a href="index.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image16','','images/home/home_on.gif',1)"><img src="images/home/home_off.gif" name="Image16" width="59" height="20" border="0"></a></td>
        </tr>
      </table></td>
  </tr>
  <tr> 
    <td align="right" background="images/nav/guitar_bar_tile.gif"><img src="images/nav/guitar_bar.gif" width="780" height="50"></td>
  </tr>
  <tr> 
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td height="53" background="images/nav/title_tile.gif"><img src="images/nav/lt_toptable.gif" width="497" height="53"></td>
          <td align="right" background="images/nav/title_tile.gif"><img src="images/nav/checkout_ttl.gif" width="283" height="53"></td>
        </tr>
      </table></td>
  </tr>
  <tr> 
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td width="45" valign="top" background="images/nav/lt_midtabletile.gif"><img src="images/nav/lt_midtabletop.gif" width="45" height="242"></td>
          <td rowspan="2" valign="top" bgcolor="#FFFFFF"><table width="100%" height="527" border="0" cellpadding="20" cellspacing="0">
              <tr> 
                <td valign="top" class="bgTile"><img src="images/nav/checkout_ttl_small.gif" width="70" height="10"> 
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                      <td bgcolor="#878787"><img src="images/home/spacer.gif" width="1" height="1"></td>
                    </tr>
                  </table>
                  <p><strong><span class="standardFont">The following items are 
                    in your shopping cart</span></strong>:<br>
                  </p>
                  <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" bgcolor="#000000">
                    <TR> 
                      <TD WIDTH="100%"> <table width="100%" border="0" cellspacing="1" cellpadding="0">
                          <tr> 
                            <td bgcolor="#FFFFFF"><TABLE BORDER="0" CELLPADDING="4" CELLSPACING="0" WIDTH="100%">
                                <form name="frmCart" method="get">
                                  <TR>
                                    <TD background="images/products/table_bg.gif">&nbsp;</TD>
                                    <TD height="17" background="images/products/table_bg.gif"> 
                                      <img src="images/products/item.gif" width="26" height="9"></TD>
                                    <TD ALIGN="center" background="images/products/table_bg.gif"> 
                                      <img src="images/products/shipping.gif" width="51" height="9"></TD>
                                    <TD ALIGN="center" background="images/products/table_bg.gif"> 
                                      <img src="images/products/quantity.gif" width="57" height="9"></TD>
                                    <TD ALIGN="center" background="images/products/table_bg.gif"> 
                                      <img src="images/products/price.gif" width="33" height="9"></TD>
                                    <TD ALIGN="center" background="images/products/table_bg.gif"> 
                                      <img src="images/products/total.gif" width="37" height="9"></TD>
                                  </TR>

Reply With Quote
  #13  
Old April 18th, 2003, 07:38 AM
digital102 digital102 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 digital102 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Here is the last one, sorry!!!

PHP Code:
<?php 
while($row mysql_fetch_array($result))
{
// Increment the total cost of all items 
$totalCost += ($row["qty"] * $row["cost"]); 
$subtotal=(($row["cost"] + $row["shipping"]) * ($row["qty"]));?>
                                  <TR class="standardFont">
                                    <TD><a href="cart.php?action=remove_item&id=<?php echo $row["itemId"]; ?>">Remove</a></TD>
                                    <TD> 
                                      <?php  echo $row["title"]; ?>
                                    </TD>
                                    <TD align="center">$ 
                                      <?php  echo $row["shipping"]; ?>
                                    </TD>
                                    <TD align="center"><select name="<?php echo $row["itemId"]; ?>" onChange="UpdateQty(this)"> 
<?php 

for($i 1$i <= 20$i++) 

echo 
"<option "
if(
$row["qty"] == $i

echo 
" SELECTED "

echo 
">" $i "</option>"

?> 
</select> 
</TD>
                                    <TD align="center"><?php echo "\$"; echo $row["cost"]; ?></TD>
                                    <TD align="center">$<?php printf("%.2f",$subtotal?></TD>
                                  </TR>
                                  <?php ?>
                                  <TR class="standardFont">
                                    <TD>&nbsp;</TD>
                                    <TD>&nbsp;</TD>
                                    <TD align="center">&nbsp;</TD>
                                    <TD align="center">&nbsp;</TD>
                                    <TD align="center">&nbsp;</TD>
                                    <TD align="center">&nbsp;</TD>
                                  </TR>
                                  <TR class="standardFont"> 
                                    <TD colspan="4">Tax and Shipping:<br>
                                      Estimated tax and shipping amounts depend 
                                      on the shipping address.<br>
                                      Amounts are calculated in the checkout process 
                                      when the shipping address is provided.</TD>
                                    <TD align="center"><strong>TOTAL:</strong></TD>
                                    <TD align="center">$<?php printf("%.2f",$totalCost?></TD>
                                  </TR>
                                  <TR align="right"> 
                                    <TD colspan="6" valign="middle"> <table border="0" cellpadding="0" cellspacing="10">
                                        <tr> 
                                          <td align="right"><input name="button" type="submit" id="button" value="Empty"> 
                                          </td>
                                          <td align="right"><input name="button" type="submit" id="button" value="Update"></td>
                                          <td width="100" align="right"><input name="submit" type="image" src="images/products/checkout.gif" width="79" height="18" border="0"></td>
                                        </tr>
                                      </table></TD>
                                  </TR>
                                  <TR bgcolor="#878787"> 
                                    <TD height="17" colspan="6" valign="middle"><img src="images/home/spacer.gif" width="1" height="1"></TD>
                                  </TR>
                                </FORM>
                              </TABLE></td>
                          </tr>
                        </table>
                  </TABLE>
                  <br> <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr> 
                      <td><a href="javascript:self.history.go(-1)"><img src="images/nav/continue_shopping.gif" width="134" height="18" border="0"></a></td>
                    </tr>
                  </table></td>
              </tr>
            </table></td>
          <td width="37" valign="top" background="images/nav/rt_midtabletile.gif"><img src="images/nav/rt_midtabletop.gif" width="37" height="242"></td>
        </tr>
        <tr> 
          <td valign="bottom" background="images/nav/lt_midtabletile.gif"><img src="images/nav/lt_midtablebottom.gif" width="45" height="285"></td>
          <td valign="bottom" background="images/nav/rt_midtabletile.gif"><img src="images/nav/rt_midtablebottom.gif" width="37" height="285"></td>
        </tr>
      </table></td>
  </tr>
  <tr> 
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td background="images/nav/bottomtable_tile.gif"><img src="images/nav/lt_bottomtable.gif" width="497" height="35"></td>
          <td align="right" background="images/nav/bottomtable_tile.gif"><img src="images/nav/rt_bottomtable.gif" width="283" height="35"></td>
        </tr>
      </table></td>
  </tr>
  <tr> 
    <td height="17" background="images/home/bottom_tile.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
</table></td>
  </tr>
</table>
</body>
</html>
<?php ?>

Reply With Quote
  #14  
Old April 18th, 2003, 07:56 AM
deedee deedee is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 11 deedee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to deedee
Let's try this:

<?php

include("db.php");
global $dbServer, $dbUser, $dbPass, $dbName;

@mysql_connect($dbServer, $dbUser, $dbPass) or die("Can't connect");
@mysql_select_db($dbName) or die("Invalid database");

?>

Reply With Quote
  #15  
Old April 18th, 2003, 08:29 AM
digital102 digital102 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 digital102 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Error found

I ran a print(mysql_error()); and I got the error below:


You have an error in your SQL syntax near 'on cart.itemId = products.id WHERE cart.cookieId = 'c8df510bf89a65218316e8ec3318' at line 1

The line of code it is referring to is:

$query = "SELECT * FROM cart INNER JOIN products on cart.itemId = products.id WHERE cart.cookieId = '" . GetCartId() . "' ORDER BY products.title ASC";

I don't see an error in syntax, do you?

Thanks again for your help!!!

Reply With Quote
  #16  
Old April 18th, 2003, 08:37 AM
deedee deedee is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 11 deedee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to deedee
What's the output of this man?
<?php

include("db.php");
global $dbServer, $dbUser, $dbPass, $dbName;

@mysql_connect($dbServer, $dbUser, $dbPass) or die("Can't connect");
@mysql_select_db($dbName) or die("Invalid database");

?>

Reply With Quote
  #17  
Old April 18th, 2003, 08:41 AM
digital102 digital102 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 digital102 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Output

I added what you suggested. But there was no output. I'll still only getting the same error from before.

Thanks again!!

Reply With Quote
  #18  
Old April 18th, 2003, 08:47 AM
deedee deedee is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 11 deedee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to deedee
Try this:

$query = "SELECT * FROM cart,products WHERE cart.itemId=products.id and cart.cookieId = \"" . GetCartId() . "\" ORDER BY products.title ASC";

Reply With Quote
  #19  
Old April 18th, 2003, 08:53 AM
digital102 digital102 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 digital102 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It finally worked

This is what I did and it finally worked:

$query = "SELECT * FROM cart,products WHERE (cart.itemId=products.id) and cart.cookieId = \"" . GetCartId() . "\" ORDER BY products.title ASC";

Thanks a lot for your help!!!!

It is greatly appreciated!!!

Reply With Quote
  #20  
Old April 18th, 2003, 08:55 AM
deedee deedee is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 11 deedee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to deedee
Ok, no problem

Have a nice weekend!

Greets,
deedee

Reply With Quote
  #21  
Old February 22nd, 2004, 02:12 PM
AGLFTL AGLFTL is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 AGLFTL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Warning: session_start()

Hi Guys!

I have a small problem - I get the following Warnings:

Warning: session_start(): open(/tmp\sess_9fb4f116aff355956dbd2e23ef7cbf09, O_RDWR) failed: No such file or directory (2) in C:\Programme\Apache Group\Apache\htdocs\herbalife\script\db.php on line 30

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Programme\Apache Group\Apache\htdocs\herbalife\html\TMP4b3yeti4xr.p hp:6) in C:\Programme\Apache Group\Apache\htdocs\herbalife\script\db.php on line 30

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Programme\Apache Group\Apache\htdocs\herbalife\html\TMP4b3yeti4xr.p hp:6) in C:\Programme\Apache Group\Apache\htdocs\herbalife\script\db.php on line 30

Warning: Cannot modify header information - headers already sent by (output started at C:\Programme\Apache Group\Apache\htdocs\herbalife\html\TMP4b3yeti4xr.p hp:6) in C:\Programme\Apache Group\Apache\htdocs\herbalife\script\db.php on line 31

The Code looks fine to me:
<?php
$dbServer = "localhost";
$dbUser = "apache";
$dbPass = "xxxxxxxxxx";
$dbName = "php_db";
function ConnectToDb($server, $user, $pass, $database)
{
$s = @mysql_connect($server, $user, $pass);
$d = @mysql_select_db($database, $s);
if(!$s || !$d)
return false;
else
return true;
}
function GetCartId()
{
if(isset($_COOKIE["cartId"]))
{
return $_COOKIE["cartId"];
}
else
{
session_start();
setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}
}
?>

What am I doing wrong?

Thanks!

Reply With Quote
  #22  
Old March 12th, 2004, 12:04 AM
ajrulez ajrulez is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 5 ajrulez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Need help :(

Can someone help me with cart.php script? I am confused since the script is broken into pieces here I'd appreciate any kind of help.


Thanks

Reply With Quote
  #23  
Old March 12th, 2004, 12:08 AM
ajrulez ajrulez is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 5 ajrulez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Solved

Sorry....duplicated my earlier post.

Reply With Quote
  #24  
Old March 12th, 2004, 08:11 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 7
Send a message via MSN to Spongy
Suggest you place a new thread for your problem.
__________________
Work to live, don't live to work

Reply With Quote
  #25  
Old March 12th, 2004, 10:10 AM
ajrulez ajrulez is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 5 ajrulez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for your suggestion, I'm gonna start a new thread


Regards,

AJ

Reply With Quote
  #26  
Old April 7th, 2004, 05:39 AM
topper topper is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 topper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
If anyone else is looking for the files that go with this article you can find them on the Macromedia site - URL

I've no idea why they are not on the devarticles site - the way the tutorial is written requires the files (IMHO).

Anyway. good luck.

Topper

Reply With Quote
  #27  
Old May 13th, 2004, 10:10 PM
titoc titoc is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 5 titoc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 42 sec
Reputation Power: 0
Question Problem with totalCost

I'm having this problem:
Notice: Undefined variable: sql_result in C:\Programas\Apache Group\Apache2\htdocs\page\cart.php on line 118

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Programas\Apache Group\Apache2\htdocs\page\cart.php on line 118
function UpdateQty(item) { itemId = item.name; newQty = item.options[item.selectedIndex].text; document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty; }
<< Keep Shopping Total: €
Notice: Undefined variable: totalCost in C:\Programas\Apache Group\Apache2\htdocs\page\cart.php on line 197
0.00

I think this two erros are the same. I made some changes in products.php, like substituting $results by $sql_results and worked fine. So I made the same to cart.php. I've alredy tried to rename it back and i've got the same error.
Can anyone send me an example of this working or tell me what's wrong with this?
Sorry any bad english but I'm portuguese.

Thanks!

Reply With Quote
  #28  
Old July 18th, 2004, 02:17 AM
fazz fazz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 4 fazz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mysql_fetch_array() error

hi, can anybody tell me why i get the following error when using the tutorial scripts verbatim?

Warning
: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /webroot/cart/products.php on line 42

i'm using php 4.3.3 and mysql 4.0.15a

thanks.

Reply With Quote
  #29  
Old July 18th, 2004, 03:31 AM
fazz fazz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 4 fazz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
erm, sorry i'll put this in a new thread actually...

Reply With Quote
  #30  
Old March 25th, 2005, 09:57 PM
walaale walaale is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 1 walaale User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 14 sec
Reputation Power: 0
Question SQL syntax near '' at line 1

I am getting the following error: "You have an error in your SQL syntax near '' at line 1" " When
I try to add an item into the shopping cart! Does any one know why?

Thanks,

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Building A Persistent Shopping Cart With PHP and MySQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek