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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

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

Post 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]
Last edited by Mythic Fr0st on Sun Dec 10, 2006 4:08 pm, edited 2 times in total.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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.
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

can I also ask after so many posts and so many problems why you still arent posting your code properly ?
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

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

Post 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
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

lol

Post 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]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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',
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

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

Post by volka »

Mythic Fr0st wrote:`weapon`, `spell`, `gold`, `banked gold`, `charname`,)
VALUES
The comma after charname is wrong.
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

ty

Post by Mythic Fr0st »

Thanks fixed
Post Reply