Macromedia Tutorial Broken? (MySQL + PHP cart)
Moderator: General Moderators
-
Foundation
- Forum Newbie
- Posts: 13
- Joined: Mon Mar 24, 2003 9:06 pm
Macromedia Tutorial Broken? (MySQL + PHP cart)
http://www.macromedia.com/devnet/mx/dre ... _cart.html
This is my first post, and I'm just getting into PHP/MySQL. Also, this is in no way to promote Macromedia. I just wanted to post a link to their tute. I set up MySQL and PHP and both test fine and seem to work fine, but using their files and creating the db as they tell me to, I consistantly get errors about:
mysql_fetch_array(): supplied argument is not a valid MySQL result resource
I know it's a generic error, but can someone please help me with this? I think if I can get through this tute, I'll be well on my way down the PHP road.
Thanks in advance.
This is my first post, and I'm just getting into PHP/MySQL. Also, this is in no way to promote Macromedia. I just wanted to post a link to their tute. I set up MySQL and PHP and both test fine and seem to work fine, but using their files and creating the db as they tell me to, I consistantly get errors about:
mysql_fetch_array(): supplied argument is not a valid MySQL result resource
I know it's a generic error, but can someone please help me with this? I think if I can get through this tute, I'll be well on my way down the PHP road.
Thanks in advance.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
Foundation
- Forum Newbie
- Posts: 13
- Joined: Mon Mar 24, 2003 9:06 pm
This is the code from db.php for the connection:
..and here are the blocks of php in products.php that it stumbles on:
and the actual error occurs on the line:
..from the block:
Sorry for the long post but I think that the error could be anywhere in there. I recreated the db three times based on their instructions, and this is the "finished product" code that you download.
Thanks!
Code: Select all
<?php
// This page contains the connection routine for the
// database as well as getting the ID of the cart, etc
$dbServer = "localhost";
$dbUser = "admin";
$dbPass = "password";
$dbName = "cart";
function ConnectToDb($server, $user, $pass, $database)
{
// Connect to the database and return
// true/false depending on whether or
// not a connection could be made.
$s = @mysql_connect($server, $user, $pass);
$d = @mysql_select_db($database, $s);
if(!$s || !$d)
return false;
else
return true;
}
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();
}
}
?>Code: Select all
<?php
// This page will list all of the items
// from the items table. Each item will have
// a link to add it to the cart
include("db.php");
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$result = mysql_query("select * from items order by itemName asc");
?>Code: Select all
while($row = mysql_fetch_array($result))Code: Select all
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td width="30%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $rowї"itemName"]; ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
$<?php echo $rowї"itemPrice"]; ?>
</font>
</td>
<td width="50%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $rowї"itemDesc"]; ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<a href="cart.php?action=add_item&id=<?php echo $rowї"itemId"]; ?>&qty=1">Add Item</a>
</font>
</td>
</tr>
<tr>
<td width="100%" colspan="4">
<hr size="1" color="red" NOSHADE>
</td>
</tr>
<?php
}
?>Thanks!
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Best to add some database debugging by adding in some or die() statements and calls to mysql_error(). Try changing the ConnectToDB() function to:
Then where you have calls to mysql_query() like this:
Change them to look like this:
Hopefully that will help you get a more meaningful error message.
Mac
Code: Select all
function ConnectToDb($server, $user, $pass, $database)
{
// Connect to the database and return
// true/false depending on whether or
// not a connection could be made.
// adding the or die() statements will allow you to find out if the
// connection or database selection are going wrong
$s = @mysql_connect($server, $user, $pass) or die(mysql_error());
$d = @mysql_select_db($database, $s) or die(mysql_error());
if(!$s || !$d)
return false;
else
return true;
}Code: Select all
$result = mysql_query("select * from items order by itemName asc");Code: Select all
$sql = "SELECT * FROM items ORDER BY itemName ASC";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');Mac
-
Foundation
- Forum Newbie
- Posts: 13
- Joined: Mon Mar 24, 2003 9:06 pm
I did add those from what you had posted to previous posts about that error. It says for:
..that no database is selected.
I'll add those other parts now and see what I get.
Edit:
I installed those that you suggested and got this only on the screen:
Access denied for user: 'admin@127.0.0.1' (Using password: YES)
So is it db related then? I'm running WinXP/IIS4+/PHP4/MySQL.
Code: Select all
$sql = "SELECT * FROM items ORDER BY itemName ASC";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');I'll add those other parts now and see what I get.
Edit:
I installed those that you suggested and got this only on the screen:
Access denied for user: 'admin@127.0.0.1' (Using password: YES)
So is it db related then? I'm running WinXP/IIS4+/PHP4/MySQL.
-
phpfreak
- Forum Commoner
- Posts: 30
- Joined: Fri Mar 21, 2003 10:28 am
- Location: New Jersey,USA
- Contact:
this works fine!!!
hi foundation,
the zip file i am sending including the database works perfect just check it.
I changed the following:
1) I made $dbUser = "";$dbPass = ""; null.
2) I inserted the <?php } ?> in the products.php
the files in order:
-----------------------------------------------------------------------------
db.php
==========
<?php
// This page contains the connection routine for the
// database as well as getting the ID of the cart, etc.
$dbServer = "localhost";
$dbUser = "";
$dbPass = "";
$dbName = "cart";
function ConnectToDb($server, $user, $pass, $database)
{
// Connect to the database and return
// true/false depending on whether or
// not a connection could be made.
$s = @mysql_connect($server, $user, $pass);
$d = @mysql_select_db($database, $s);
if(!$s || !$d)
return false;
else
return true;
}
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();
}
}
?>
------------------------------------------------------------------------
products.php
=============
<?php
// This page will list all of the items
// from the items table. Each item will have
// a link to add it to the cart
include("db.php");
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$result = mysql_query("select * from items order by itemName asc");
?>
<html>
<head>
</head>
<body>
<h2 align="left">Products </h2>
<table>
<tr>
<th width="30%" bgcolor="orange"><font face="verdana" size="1" color="black"> Product</font></th>
<th width="10%" bgcolor="orange"><font face="verdana" size="1" color="black">Price</font></th>
<th width="50%" bgcolor="orange"><font face="verdana" size="1" color="black">Description</font></th>
<th width="10%" bgcolor="orange"><font face="verdana" size="1" color="black">Add</font></th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td width="30%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["itemName"]; ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
$<?php echo $row["itemPrice"]; ?>
</font>
</td>
<td width="50%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["itemDesc"]; ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<a href="cart.php?action=add_item&id=<?php echo $row["itemId"]; ?>&qty=1">Add Item</a>
</font>
</td>
</tr>
<tr>
<td width="100%" colspan="4">
<hr size="1" color="red" NOSHADE>
</td>
</tr>
<?php
}
?>
<tr>
<td width="100%" colspan="4">
<font face="verdana" size="1" color="black">
<a href="cart.php">Your Shopping Cart >></a>
</font>
</td>
</tr>
</table>
</body>
</html>
============================================
cart.php
=======
<?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
$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
$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;
$result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc");
?>
<html>
<head>
<title> Your Shopping Cart </title>
<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>
</head>
<body bgcolor="#ffffff">
<h1>Your Shopping Cart</h1>
<form name="frmCart" method="get">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="15%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Qty</b>
</font>
</td>
<td width="55%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Product</b>
</font>
</td>
<td width="20%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Price Each</b>
</font>
</td>
<td width="10%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Remove?</b>
</font>
</td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["itemPrice"]);
?>
<tr>
<td width="15%" height="25">
<font face="verdana" size="1" color="black">
<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>
</font>
</td>
<td width="55%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["itemName"]; ?>
</font>
</td>
<td width="20%" height="25">
<font face="verdana" size="1" color="black">
$<?php echo number_format($row["itemPrice"], 2, ".", ","); ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<a href="cart.php?action=remove_item&id=<?php echo $row["itemId"]; ?>">Remove</a>
</font>
</td>
</tr>
<?php
}
// Display the total
?>
<tr>
<td width="100%" colspan="4">
<hr size="1" color="red" NOSHADE>
</td>
</tr>
<tr>
<td width="70%" colspan="2">
<font face="verdana" size="1" color="black">
<a href="products.php"><< Keep Shopping</a>
</font>
</td>
<td width="30%" colspan="2">
<font face="verdana" size="2" color="black">
<b>Total: $<?php echo number_format($totalCost, 2, ".", ","); ?></b>
</font>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
?>
======================================
I think the problem is in the db file because of the user authentication.
i hope this helps .
regards
srinivas
the zip file i am sending including the database works perfect just check it.
I changed the following:
1) I made $dbUser = "";$dbPass = ""; null.
2) I inserted the <?php } ?> in the products.php
the files in order:
-----------------------------------------------------------------------------
db.php
==========
<?php
// This page contains the connection routine for the
// database as well as getting the ID of the cart, etc.
$dbServer = "localhost";
$dbUser = "";
$dbPass = "";
$dbName = "cart";
function ConnectToDb($server, $user, $pass, $database)
{
// Connect to the database and return
// true/false depending on whether or
// not a connection could be made.
$s = @mysql_connect($server, $user, $pass);
$d = @mysql_select_db($database, $s);
if(!$s || !$d)
return false;
else
return true;
}
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();
}
}
?>
------------------------------------------------------------------------
products.php
=============
<?php
// This page will list all of the items
// from the items table. Each item will have
// a link to add it to the cart
include("db.php");
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$result = mysql_query("select * from items order by itemName asc");
?>
<html>
<head>
</head>
<body>
<h2 align="left">Products </h2>
<table>
<tr>
<th width="30%" bgcolor="orange"><font face="verdana" size="1" color="black"> Product</font></th>
<th width="10%" bgcolor="orange"><font face="verdana" size="1" color="black">Price</font></th>
<th width="50%" bgcolor="orange"><font face="verdana" size="1" color="black">Description</font></th>
<th width="10%" bgcolor="orange"><font face="verdana" size="1" color="black">Add</font></th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td width="30%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["itemName"]; ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
$<?php echo $row["itemPrice"]; ?>
</font>
</td>
<td width="50%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["itemDesc"]; ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<a href="cart.php?action=add_item&id=<?php echo $row["itemId"]; ?>&qty=1">Add Item</a>
</font>
</td>
</tr>
<tr>
<td width="100%" colspan="4">
<hr size="1" color="red" NOSHADE>
</td>
</tr>
<?php
}
?>
<tr>
<td width="100%" colspan="4">
<font face="verdana" size="1" color="black">
<a href="cart.php">Your Shopping Cart >></a>
</font>
</td>
</tr>
</table>
</body>
</html>
============================================
cart.php
=======
<?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
$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
$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;
$result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc");
?>
<html>
<head>
<title> Your Shopping Cart </title>
<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>
</head>
<body bgcolor="#ffffff">
<h1>Your Shopping Cart</h1>
<form name="frmCart" method="get">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="15%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Qty</b>
</font>
</td>
<td width="55%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Product</b>
</font>
</td>
<td width="20%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Price Each</b>
</font>
</td>
<td width="10%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Remove?</b>
</font>
</td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["itemPrice"]);
?>
<tr>
<td width="15%" height="25">
<font face="verdana" size="1" color="black">
<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>
</font>
</td>
<td width="55%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["itemName"]; ?>
</font>
</td>
<td width="20%" height="25">
<font face="verdana" size="1" color="black">
$<?php echo number_format($row["itemPrice"], 2, ".", ","); ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<a href="cart.php?action=remove_item&id=<?php echo $row["itemId"]; ?>">Remove</a>
</font>
</td>
</tr>
<?php
}
// Display the total
?>
<tr>
<td width="100%" colspan="4">
<hr size="1" color="red" NOSHADE>
</td>
</tr>
<tr>
<td width="70%" colspan="2">
<font face="verdana" size="1" color="black">
<a href="products.php"><< Keep Shopping</a>
</font>
</td>
<td width="30%" colspan="2">
<font face="verdana" size="2" color="black">
<b>Total: $<?php echo number_format($totalCost, 2, ".", ","); ?></b>
</font>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
?>
======================================
I think the problem is in the db file because of the user authentication.
i hope this helps .
regards
srinivas
-
Foundation
- Forum Newbie
- Posts: 13
- Joined: Mon Mar 24, 2003 9:06 pm
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
Foundation
- Forum Newbie
- Posts: 13
- Joined: Mon Mar 24, 2003 9:06 pm
Ok, I tried the cart page and get multiple errors as follows:
Warning: session_start() [function.session-start]: open(/tmp\sess_896dc46659c8a15e053f4d97d5d967f6, O_RDWR) failed: No such file or directory (2) in C:\Inetpub\wwwroot\phpcart\db.php on line 41
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Inetpub\wwwroot\phpcart\db.php:41) in C:\Inetpub\wwwroot\phpcart\db.php on line 41
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\wwwroot\phpcart\db.php:41) in C:\Inetpub\wwwroot\phpcart\db.php on line 41
Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\wwwroot\phpcart\db.php:41) in C:\Inetpub\wwwroot\phpcart\db.php on line 42
Your Shopping Cart
Qty Product Price Each Remove?
--------------------------------------------------------------------------------
<< Keep Shopping Total: $0.00
Warning: Unknown(): open(/tmp\sess_896dc46659c8a15e053f4d97d5d967f6, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0
..any ideas? I used the code exactly as listed by phpfreak.
Warning: session_start() [function.session-start]: open(/tmp\sess_896dc46659c8a15e053f4d97d5d967f6, O_RDWR) failed: No such file or directory (2) in C:\Inetpub\wwwroot\phpcart\db.php on line 41
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Inetpub\wwwroot\phpcart\db.php:41) in C:\Inetpub\wwwroot\phpcart\db.php on line 41
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\wwwroot\phpcart\db.php:41) in C:\Inetpub\wwwroot\phpcart\db.php on line 41
Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\wwwroot\phpcart\db.php:41) in C:\Inetpub\wwwroot\phpcart\db.php on line 42
Your Shopping Cart
Qty Product Price Each Remove?
--------------------------------------------------------------------------------
<< Keep Shopping Total: $0.00
Warning: Unknown(): open(/tmp\sess_896dc46659c8a15e053f4d97d5d967f6, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0
..any ideas? I used the code exactly as listed by phpfreak.
-
phpfreak
- Forum Commoner
- Posts: 30
- Joined: Fri Mar 21, 2003 10:28 am
- Location: New Jersey,USA
- Contact:
hi there,
I thought it worked the first time you tried, anyway can u please let me know what your version of php is??
secondly is your iis or apache server on???
if your php version is 4.2 then we have to think about the register_globals parameter in your php.ini file.
do me another favour just check to see if you the products.php is working and try to navigate from products.php
regards
srinivas
I thought it worked the first time you tried, anyway can u please let me know what your version of php is??
secondly is your iis or apache server on???
if your php version is 4.2 then we have to think about the register_globals parameter in your php.ini file.
do me another favour just check to see if you the products.php is working and try to navigate from products.php
regards
srinivas
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
This is the important error:
Basically you need to set a location for session files to be stored in your php.ini. I'm assuming you're on Windows in which case you'll find the file in your C:\WINDOWS or C:\WINNT (depending on your Windows version).
You need to edit this bit:
For example if you decided to save sessions to C:\PHP\sessionstuff, you'd create the folder and then change:
to
Mac
all of the other errors are being caused by it being displayed.Warning: session_start() [function.session-start]: open(/tmp\sess_896dc46659c8a15e053f4d97d5d967f6, O_RDWR) failed: No such file or directory (2) in C:\Inetpub\wwwroot\phpcart\db.php on line 41
Basically you need to set a location for session files to be stored in your php.ini. I'm assuming you're on Windows in which case you'll find the file in your C:\WINDOWS or C:\WINNT (depending on your Windows version).
You need to edit this bit:
Code: Select all
; Argument passed to save_handler. In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this
; variable in order to use PHP's session functions.
session.save_path = /tmpCode: Select all
session.save_path = /tmpCode: Select all
session.save_path = C:\PHP\sessionstuff- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
Foundation
- Forum Newbie
- Posts: 13
- Joined: Mon Mar 24, 2003 9:06 pm
phpfreak -
The IIS was started, PHP is 4.3.1. What worked first try is the products.php page, and I wasn't able to try the cart page until I got home. Thank you again for all your help.
twigletmac -
I changed my php.ini to point the session.save_path = c:\PHP\tmp and created a tmp directory there and now it seems to work fine! I was able to add, remove, and change quantities from the cart.
Thanks again for the help. I really like these forums and hopefully with a little time, I'll be able to contribute.
The IIS was started, PHP is 4.3.1. What worked first try is the products.php page, and I wasn't able to try the cart page until I got home. Thank you again for all your help.
twigletmac -
I changed my php.ini to point the session.save_path = c:\PHP\tmp and created a tmp directory there and now it seems to work fine! I was able to add, remove, and change quantities from the cart.
Thanks again for the help. I really like these forums and hopefully with a little time, I'll be able to contribute.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK