Page 1 of 1

Pls help...mind blank.

Posted: Thu Jul 16, 2009 9:12 am
by WhizzBang
Hey everyone, i'm having trouble inserting into the DB.

This is for a game engine...

Code: Select all

$insert = sprintf("INSERT INTO heist (crime_type, amount_joined , crimeName , maxmemmbers , minmoney , maxmoney , staff , userid) VALUES (Rob A Local Bank, 1,%s, 10, 1000, 5000 , 2 , %s)",  mysql_real_escape_string(htmlentities($_POST['crimeName'])) , $userid);
 
mysql_query($insert);
Can anyone see whats wrong?...I know this is something simple...lol

Code: Select all

`crime_id` int(11) NOT NULL auto_increment,
  `crime_type` varchar(255) NOT NULL default '0',
  `amount_joined` int(11) NOT NULL default '0',
  `crimeName` varchar(255) NOT NULL default 'Defualt',
  `maxmembers` int(11) NOT NULL default '10',
  `minmoney` int(11) NOT NULL default '0',
  `maxmoney` int(11) NOT NULL default '0',
  `staff` int(11) NOT NULL default '0',
  `userid` int(11) NOT NULL,
  KEY `crime_id` (`crime_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
This is the DB table...

Thanks in advance :)

Re: Pls help...mind blank.

Posted: Thu Jul 16, 2009 9:18 am
by aliciadg
Are you getting a specific error or simply no data added to your DB? Have you tried placing quotes around your values?

Re: Pls help...mind blank.

Posted: Thu Jul 16, 2009 9:21 am
by WhizzBang
No data is getting sent to the DB..

I've tried placing quotes but that didn't work...

I've echo'd out the $_POST['crimeName'] and that show's perfect so I know the $_POST is working...:S

Re: Pls help...mind blank.

Posted: Thu Jul 16, 2009 9:36 am
by aliciadg
Trying to wrap my head wround your script...these are all the values being written to the DB?

Code: Select all

(Rob A Local Bank, 1,%s, 10, 1000, 5000 , 2 , %s)",  mysql_real_escape_string(htmlentities($_POST['crimeName'])) , $userid);
If so it seems like your closing the parenthesis and quotes on values too soon.
Also for the sake of testing have you tried this:

Code: Select all

$CN=mysql_real_escape_string(htmlentities($_POST['crimeName'])
 *your insert statement with values
(Rob A Local Bank, 1,%s, 10, 1000, 5000 , 2 , %s,  $CN , $userid);
Hope I'm not confusing your further :)
EDITED

Re: Pls help...mind blank.

Posted: Thu Jul 16, 2009 9:57 am
by jackpf
For god's sake, if your query is failing put "or die(mysql_error());" after it.

Re: Pls help...mind blank.

Posted: Thu Jul 16, 2009 9:58 am
by spider.nick
jackpf wrote:For god's sake, if your query is failing put "or die(mysql_error());" after it.
Not really sure that God is having an issue with the query ... I could be wrong, though.

Nick

Re: Pls help...mind blank.

Posted: Thu Jul 16, 2009 10:06 am
by WhizzBang
I'm so sorry this was possible the most stupid error ive ever had :P

I named some of the data wrong rofl

Re: Pls help...mind blank.

Posted: Thu Jul 16, 2009 10:08 am
by jackpf
spider.nick wrote:
jackpf wrote:For god's sake, if your query is failing put "or die(mysql_error());" after it.
Not really sure that God is having an issue with the query ... I could be wrong, though.

Nick
If I was God and I saw someone not putting that after the query when it was failing, I'd have an issue with it.

However, it wouldn't have shown that you were using the wrong data....But still, in the future, always append that to your queries if they're not working. It'll save you a heap of bother.

Re: Pls help...mind blank.

Posted: Thu Jul 16, 2009 10:13 am
by WhizzBang
I'll take that advice :)

I've really only just started PHP developing and I really enjoy it and doing very well lol

Re: Pls help...mind blank.

Posted: Thu Jul 16, 2009 10:52 am
by jackpf
Ahh, well sorry for being a bit excessive then :P

Good luck.