Pls help...mind blank.

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
WhizzBang
Forum Newbie
Posts: 11
Joined: Sat Jul 11, 2009 5:39 pm

Pls help...mind blank.

Post 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 :)
aliciadg
Forum Newbie
Posts: 16
Joined: Tue Jul 14, 2009 3:39 pm

Re: Pls help...mind blank.

Post by aliciadg »

Are you getting a specific error or simply no data added to your DB? Have you tried placing quotes around your values?
WhizzBang
Forum Newbie
Posts: 11
Joined: Sat Jul 11, 2009 5:39 pm

Re: Pls help...mind blank.

Post 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
aliciadg
Forum Newbie
Posts: 16
Joined: Tue Jul 14, 2009 3:39 pm

Re: Pls help...mind blank.

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Pls help...mind blank.

Post by jackpf »

For god's sake, if your query is failing put "or die(mysql_error());" after it.
spider.nick
Forum Commoner
Posts: 72
Joined: Wed Jul 15, 2009 12:22 pm
Location: Overland Park, KS

Re: Pls help...mind blank.

Post 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
WhizzBang
Forum Newbie
Posts: 11
Joined: Sat Jul 11, 2009 5:39 pm

Re: Pls help...mind blank.

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Pls help...mind blank.

Post 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.
WhizzBang
Forum Newbie
Posts: 11
Joined: Sat Jul 11, 2009 5:39 pm

Re: Pls help...mind blank.

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Pls help...mind blank.

Post by jackpf »

Ahh, well sorry for being a bit excessive then :P

Good luck.
Post Reply