R1der Posted December 11, 2006 Share Posted December 11, 2006 for some reason my code dont seem to be inserting into the database.[code]mysql_query("INSERT INTO pets_owned VALUES('', $userid, $pet, 1, 1, 1)", $c);[/code]Can you spot a problem with this?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/ Share on other sites More sharing options...
black.horizons Posted December 11, 2006 Share Posted December 11, 2006 whats the $c doing outside the rest of the ""smysql_query("INSERT INTO pets_owned VALUES('', $userid, $pet, 1, 1, 1, $c"); Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138955 Share on other sites More sharing options...
HuggieBear Posted December 11, 2006 Share Posted December 11, 2006 Can I give you some advice...Always echo the error out when developing...[code]<?php$sql = "INSERT INTO pets_owned VALUES('', $userid, $pet, 1, 1, 1)";$result = mysql_query($sql, $c);if (!$result){ echo "Couldn't execute $sql:" . mysql_error();}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138957 Share on other sites More sharing options...
HuggieBear Posted December 11, 2006 Share Posted December 11, 2006 [quote author=black.horizons link=topic=118177.msg482611#msg482611 date=1165841583]whats the $c doing outside the rest of the ""smysql_query("INSERT INTO pets_owned VALUES('', $userid, $pet, 1, 1, 1, $c");[/quote]$c is the connection resource.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138958 Share on other sites More sharing options...
R1der Posted December 11, 2006 Author Share Posted December 11, 2006 Thakns for the replys.huggiei get this error when trying your codeParse error: syntax error, unexpected ';' in /blah/blah/blah/petshop.php on line 34 Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138961 Share on other sites More sharing options...
R1der Posted December 11, 2006 Author Share Posted December 11, 2006 ok its working now strange lol.i get this nowCouldn't execute INSERT INTO pets_owned VALUES('', 1, 1, 1, 1, 1):Column count doesn't match value count at row 1You bought a Greyhound / Poodle! Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138962 Share on other sites More sharing options...
R1der Posted December 11, 2006 Author Share Posted December 11, 2006 Ok i fixed it nowThx for your help :) Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138964 Share on other sites More sharing options...
HuggieBear Posted December 11, 2006 Share Posted December 11, 2006 This is because you're only inserting 6 columns and your table obviously has more than 6 columns.Try naming the columns if you're only doing a partial insert...[color=green]INSERT INTO pets_owned (columnA, columnB, columnC) VALUES ('', 1, 1)[/color]If you're leaving the first column blank as it's an auto-increment field, then there's no need to include it at all...[color=green]INSERT INTO pets_owned (columnB, columnC) VALUES (1, 1)[/color]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138965 Share on other sites More sharing options...
R1der Posted December 11, 2006 Author Share Posted December 11, 2006 ok come across another problem lol.when trying to buy a pet i get thisCouldn't execute INSERT INTO pets_owned VALUES('' 1, 1, 1, 1, 1):You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1, 1, 1, 1, 1)' at line 1the first 1 being the pet id second being the userid third , forth and fifth being strength,agility,guardAnyone have any ideas? let me know if ya wanna see code Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138980 Share on other sites More sharing options...
HuggieBear Posted December 11, 2006 Share Posted December 11, 2006 Yes, can you post that snippet of code.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138982 Share on other sites More sharing options...
R1der Posted December 11, 2006 Author Share Posted December 11, 2006 [code]$sql = "INSERT INTO pets_owned VALUES('' $pet, $userid, 1, 1, 1)";$result = mysql_query($sql, $c);if (!$result){ echo "Couldn't execute $sql:" . mysql_error();}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138985 Share on other sites More sharing options...
HuggieBear Posted December 11, 2006 Share Posted December 11, 2006 OK, what's the first field then?You've mentioned five columns, but you're trying to insert six values!RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138986 Share on other sites More sharing options...
R1der Posted December 11, 2006 Author Share Posted December 11, 2006 $sql = "INSERT INTO pets_owned VALUES(''$pet, $userid, 1, 1, 1)";$result = mysql_query($sql, $c);if (!$result){ echo "Couldn't execute $sql:" . mysql_error();}I think i posted the wrong code b4 Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138989 Share on other sites More sharing options...
HuggieBear Posted December 11, 2006 Share Posted December 11, 2006 OK, lets ties this up once and for all... How many columns are in your database table and what are they called?This is correct if you have six columns, you just need to add a comma$sql = "INSERT INTO pets_owned VALUES(''[color=red],[/color] $pet, $userid, 1, 1, 1)";Huggie Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138991 Share on other sites More sharing options...
R1der Posted December 11, 2006 Author Share Posted December 11, 2006 There are 5i have just fixed iti removed "from(''$petThanks for all your help Quote Link to comment https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138993 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.