Jump to content

Recommended Posts

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]

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138957
Share on other sites

[quote author=black.horizons link=topic=118177.msg482611#msg482611 date=1165841583]
whats the $c doing outside the rest of the ""s

mysql_query("INSERT INTO pets_owned VALUES('', $userid, $pet, 1, 1, 1, $c");
[/quote]

$c is the connection resource.

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138958
Share on other sites

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]

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138965
Share on other sites

ok come across another problem lol.

when trying to buy a pet i get this

Couldn'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 1


the first 1 being the pet id second being the userid third , forth and fifth being strength,agility,guard

Anyone have any ideas? let me know if ya wanna see code
Link to comment
https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138980
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/30226-insert-problem/#findComment-138991
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.