PHP error mysql 
June 15th, 2009, 08:45 PM
| | Newbie | | Join Date: Jun 2009 Location: Australia
Posts: 16
| | - if (IN PHP) I call $cart->insert_Pcart($item1, $item2);
-
-
-
-
class Cart
-
{
-
:
-
function insert_Pcart($item_name,$p_qty)
-
{
-
$insert = "INSERT INTO Cart (pname, qty)
-
VALUES ($_POST[$item_name]','$_POST[$p_qty]')";
- Line69=> if (mysql_query($insert, $conn)) { $cartID = mysql_insert_id($conn);
-
-
} else { die ("Error inserting CART FORM data: " .mysql_error()); };
-
-
//$p_name=($_REQUEST["p_name"]);
-
}
I get the error
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\phpdev\www\project_shopping_cart.php on line 69
Error inserting CART FORM data:
Can anyone explain what this error means or how I might fix it?
Last edited by Markus; June 15th, 2009 at 09:15 PM.
Reason: Added [code] tags.
| 
June 15th, 2009, 09:17 PM
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,862
Provided Answers: 9 | | | re: PHP error mysql Quote:
Originally Posted by toadstool - if (IN PHP) I call $cart->insert_Pcart($item1, $item2);
-
-
-
-
class Cart
-
{
-
:
-
function insert_Pcart($item_name,$p_qty)
-
{
-
$insert = "INSERT INTO Cart (pname, qty)
-
VALUES ($_POST[$item_name]','$_POST[$p_qty]')";
- Line69=> if (mysql_query($insert, $conn)) { $cartID = mysql_insert_id($conn);
-
-
} else { die ("Error inserting CART FORM data: " .mysql_error()); };
-
-
//$p_name=($_REQUEST["p_name"]);
-
}
I get the error
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\phpdev\www\project_shopping_cart.php on line 69
Error inserting CART FORM data:
Can anyone explain what this error means or how I might fix it? | It means you're trying to supply a MYSQL-Link resource that isn't valid, that is, your $conn variable isn't a valid resource. You don't seem to set it anywhere, so why pass it? You can remove this and try again. If no resource is provided, MySQL will take the current (or last opened, I forget) link.
| 
June 15th, 2009, 09:26 PM
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,487
Provided Answers: 9 | | | re: PHP error mysql Quote:
Originally Posted by toadstool Can anyone explain what this error means or how I might fix it? | this means that the 2nd parameter ($conn) is of the wrong type (it must be a resource type)
did you define $conn in the function (otherwise it is NULL, which is not a resource type)? probably the best is omitting that parameter (except you have more than one connection open, in this case you application needs aredesign)
darn…
| 
June 15th, 2009, 10:43 PM
| | Newbie | | Join Date: Jun 2009 Location: Australia
Posts: 16
| | | re: PHP error mysql
Interestingly, this did not produce an error -
function connect_cart()
-
{
-
$conn = @mysql_connect($this->host,$this->user,$this->pass);
-
if (!$conn) { die("Connection failed: " .mysql_error());}
-
if (mysql_select_db("test", $conn)) {
-
} else { die ("Could not locate test database " .mysql_error());}
-
}
-
| 
June 15th, 2009, 11:14 PM
| | Newbie | | Join Date: Jun 2009 Location: Australia
Posts: 16
| | | re: PHP error mysql
If I want to set a cookie from this wouldn't removing $conn affect this?
e.g.
$whatever = mysql_insert_id($conn);
setcookie("cookiename",$whatever);
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,689 network members.
|