Page 1 of 1

error with my SQL syntax, hmm? (inserting into MySQL)

Posted: Sun Dec 10, 2006 5:42 am
by Mythic Fr0st
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Not sure why im getting this, -.-
but I need help with it:/

Code: Select all

$con3 = mysql_connect("localhost","root","");
if (!$con3)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("chars", $con3);

 $sql3="INSERT INTO $tcn (
`strlvl`, `strdmg`, `strxp`,
`strdiv`, `dexlvl`, `dexcth`,`dexxp`, `dexdiv`, `currlife`,
`currmaxlife`, `deflvl`, `defxp`, `defda`, `intlvl`, `intxp`, `foclvl`, `focxp`, `mag`,
`weapon`, `spell`, `gold`, `banked gold`, `charname`,) 
VALUES ('4','1','0','1','4','0','0','1','13','13','4','0','0','4','0','4','0','13',
'Fists','Ignite','0','10','$tcn')";

if (!mysql_query($sql3,$con3)) 
{ 
     die('<font color="blue" size="3"><i> Error: ' . mysql_error()) . '</font></i>'; 
}
(closes later) it said error with the ,)VALUES (the following digits)

sorry to ask so much lolz, nearly 90 posts, 4 days XD


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Dec 10, 2006 5:47 am
by anjanesh
I guess the field count is wrong.
For long INSERTs, SET is better

Code: Select all

INSERT INTO $tcn SET 
`strlvl` = '4',
`strdmg` = '1',
`strxp` = '0',
`banked gold` = '10'
`charname` = ''
Also, you have a comma (,) after `charname` in your SQL statement.

Posted: Sun Dec 10, 2006 6:14 am
by evilchris2003
can I also ask after so many posts and so many problems why you still arent posting your code properly ?

Re: error with my SQL syntax, hmm? (inserting into MySQL)

Posted: Sun Dec 10, 2006 6:55 am
by hrubos
Mythic Fr0st wrote:Not sure why im getting this, -.-
but I need help with it:/

$con3 = mysql_connect("localhost","root","");
if (!$con3)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("chars", $con3);

$sql3="INSERT INTO $tcn (
`strlvl`, `strdmg`, `strxp`,
`strdiv`, `dexlvl`, `dexcth`,`dexxp`, `dexdiv`, `currlife`,
`currmaxlife`, `deflvl`, `defxp`, `defda`, `intlvl`, `intxp`, `foclvl`, `focxp`, `mag`,
`weapon`, `spell`, `gold`, `banked gold`, `charname`,)
VALUES ('4','1','0','1','4','0','0','1','13','13','4','0','0','4','0','4','0','13',
'Fists','Ignite','0','10','$tcn')";

if (!mysql_query($sql3,$con3))
{
die('<font color="blue" size="3"><i> Error: ' . mysql_error()) . '</font></i>';
}

(closes later) it said error with the ,)VALUES (the following digits)

sorry to ask so much lolz, nearly 90 posts, 4 days XD
or :

Code: Select all

$sql3="INSERT INTO $tcn (
strlvl, strdmg, strxp,
strdiv, dexlvl, dexcth,dexxp, dexdiv, currlife,
currmaxlife, deflvl, defxp, defda, intlvl, intxp, foclvl, focxp, mag,
weapon, spell, gold, banked gold, charname,) 
VALUES ('4','1','0','1','4','0','0','1','13','13','4','0','0','4','0','4','0','13',
'Fists','Ignite','0','10','$tcn')";
You can post code after cliking PHP button (near button quote). do you see it?It 's better for us to read code

lol

Posted: Sun Dec 10, 2006 3:57 pm
by Mythic Fr0st
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


z ok, Code

Not sure why, its still not working (getting closer though)
I keep getting this, on the first line it says

Code: Select all

unknown column for `strlvl` = (this part>)`4`,
(thispart> isnt actually in the code btw lol)

Code: Select all

Error: Unknown column '4' in 'field list'
hmm? perhaps resort back to VALUES or what am I doing wrong I cant see it -.-

heres my code so far

Code: Select all

$c = mysql_connect("localhost","root","");
if (!$c)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("chars", $c);
$tcn=$_POST['username'];
 $s="INSERT INTO chars SET
`strlvl` = `4`,
`strdmg` = `1`,
`strxp` = `0`,
`strdiv` = `1`,
`dexlvl` = `4`,
`dexcth`= `0`,
`dexxp` = `0`,
`dexdiv` = `1`,
`currlife` = `13`,
`maxlife` = `13`,
`deflvl` = `2`,
`defxp` = `0`,
`defda` = `0`,
`intlvl`= `4`,
`intxp` = `0`,
`foclvl`=  `4`,
`focxp` = `0`,
`mag`= `13`,
`weapon`= `Fists`,
`charname` = `Fists`,
`spell` = `Shockwave`,
`spelltype` =`lightning`,
`gold` = `0`,
`bankedgold` = `10`";

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Dec 10, 2006 4:17 pm
by John Cartwright
only column names should use backticks, string should use single quotes, and integers don't need any quotes.

`weapons` = `fists`,

changed to

`weapons` = 'fists',

Re: error with my SQL syntax, hmm? (inserting into MySQL)

Posted: Sun Dec 10, 2006 4:28 pm
by volka
Mythic Fr0st wrote:`weapon`, `spell`, `gold`, `banked gold`, `charname`,)
VALUES
The comma after charname is wrong.

ty

Posted: Sun Dec 10, 2006 4:35 pm
by Mythic Fr0st
Thanks fixed