Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP problem with adding to a DB

Status
Not open for further replies.

presfox

Technical User
Joined
Jan 30, 2004
Messages
15
Location
NL
Im using the following code:
Code:
[php]
"INSERT INTO attacks
(
    id, attackerid, attackerstatename, attackertag, defenderid, defenderstatename, defendertag, type, losses,
)
VALUES
(
    ".$arr['id'].",".$arr['attackerid'].",".$arr['attackerstatename'].",".$arr['attackertag'].",".$arr['defenderid'].",".$arr['defenderstatename'].",".$arr['defendertag'].",'".$arr['type']."','".$arr['losses']."')";
[/php]

But it gives this error:

Invalid query: 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 ') VALUES ( 1 ,3 ,Mustafa ,CM ,2 ,Svenne ,FED

Someone plz help me, the things shown in the query sofar are right
 
losses,
)

erase the , after "losses"
 
where?

in the first line or the VALUES line?

as i removed it in the first line, but the error stays the same
 
i have removed the , not the ) and it seems to work but now it gives:

Invalid query: Unknown column 'Mustafa' in 'field list'

thats the attackerstatename column
 
Code:
CREATE TABLE `attacks` (
  `id` int(12) unsigned NOT NULL default '0',
  `attackerid` int(12) unsigned NOT NULL default '0',
  `attackerstatename` varchar(30) NOT NULL default '',
  `attackertag` varchar(12) NOT NULL default '',
  `defenderid` int(12) unsigned NOT NULL default '0',
  `defenderstatename` varchar(30) NOT NULL default '',
  `defendertag` varchar(12) NOT NULL default '',
  `type` char(2) NOT NULL default '',
  `losses` varchar(12) NOT NULL default ''

the table
 
if you have the INSERT command in a variable, example:

$qry="INSERT ...."

put an echo $qry; to the program (instead the mysql_query) in order to see whether the INSERT sintax is the expected.

Pls post the result of the echo command...
 
SQL statements require that you quote string values. Otherwise they will be interpreted as part of the syntax.
Mustafa should be 'Mustafa'
 
YES!!!!

Ive tryed that before but w/o the , removed!!

now it seems to work, no errors
 
it works thanks guys :D

just checked the DB and its all in there
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top