Connecting Tech Pros Worldwide Help | Site Map

PHP error mysql

  #1  
Old June 15th, 2009, 08:45 PM
Newbie
 
Join Date: Jun 2009
Location: Australia
Posts: 16
Expand|Select|Wrap|Line Numbers
  1. if (IN PHP) I call $cart->insert_Pcart($item1, $item2);
  2.  
  3.  
  4.  
  5. class Cart 
  6. {
  7. :
  8. function insert_Pcart($item_name,$p_qty)
  9.       {
  10. $insert = "INSERT INTO Cart (pname, qty) 
  11. VALUES ($_POST[$item_name]','$_POST[$p_qty]')"; 
  12. Line69=>     if (mysql_query($insert, $conn)) { $cartID = mysql_insert_id($conn);
  13.  
  14. } else          { die ("Error inserting CART FORM data: " .mysql_error()); };
  15.  
  16. //$p_name=($_REQUEST["p_name"]);
  17. }
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.
  #2  
Old June 15th, 2009, 09:17 PM
Markus's Avatar
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 View Post
Expand|Select|Wrap|Line Numbers
  1. if (IN PHP) I call $cart->insert_Pcart($item1, $item2);
  2.  
  3.  
  4.  
  5. class Cart 
  6. {
  7. :
  8. function insert_Pcart($item_name,$p_qty)
  9.       {
  10. $insert = "INSERT INTO Cart (pname, qty) 
  11. VALUES ($_POST[$item_name]','$_POST[$p_qty]')"; 
  12. Line69=>     if (mysql_query($insert, $conn)) { $cartID = mysql_insert_id($conn);
  13.  
  14. } else          { die ("Error inserting CART FORM data: " .mysql_error()); };
  15.  
  16. //$p_name=($_REQUEST["p_name"]);
  17. }
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.
  #3  
Old June 15th, 2009, 09:26 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,487
Provided Answers: 9

re: PHP error mysql


Quote:
Originally Posted by toadstool View Post
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…
  #4  
Old 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
Expand|Select|Wrap|Line Numbers
  1. function connect_cart()
  2.       { 
  3.         $conn = @mysql_connect($this->host,$this->user,$this->pass);  
  4.        if (!$conn) { die("Connection failed: " .mysql_error());}
  5.        if (mysql_select_db("test", $conn)) { 
  6.         } else                                { die ("Could not locate test database " .mysql_error());}
  7.       }
  8.  
  #5  
Old 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);
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Error message: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/jplane/certcent/phpweb/quiz/index.php on line 20 techjohnny@gmail.com answers 2 June 16th, 2007 03:25 AM
php error newbie answers 11 February 12th, 2006 04:45 PM
About PHP::: Error/Problem PHP Warning: mysql_fetch_array(): Pratchaya answers 3 July 27th, 2005 12:15 PM
retrieve image from MySQL with php error theonlydrayk@gmail.com answers 7 July 17th, 2005 02:30 PM