Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Why wont this query work?!
Old 10-25-2008, 10:16 PM Why wont this query work?!
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
This is pretty noobish i am sure, but bit late and everyone i know which would know is offline lol so thought might get a faster answer here

And yes i know this is SQL, but i think its more likely the PHP in which might be the problem.

I have two SQL query strings one works the other dont but i cant see why =/

PHP Code:
$result "INSERT INTO `stats` stream_status='".$streamstatus."', listen='".$currentlisteners."', 
time='"
.date('Y-m-d H:i:s')."', listen_peak='".$peaklisteners."', unique_listen='".$reportedlisteners."'";
$result2 'INSERT INTO `stats` (`id`,`stream_status`,`listen`,`unique_listen`,`listen_peak`,`time`) VALUES (NULL,"'.$streamstatus.'","'.$currentlisteners.'","'.$reportedlisteners.'","'.$peaklisteners.'","'.date('Y-m-d H:i:s').'");'
$result2 works, but $result doesnt

I much prefer the $result style and want the query to be in that format but can seem to do that and make it work

can someone please advise.

TP for good answers as always!

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 10-26-2008, 03:37 AM Re: Why wont this query work?!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
INSERT only has TWO forms

INSERT INTO table VALUES(v1,v2 ...);
or
INSERT INTO table (fld1,fld2 ...) VALUES(v1,v2 ...);

The first can be used when you are inserting a value into every column, the second when all or only some of the columns are being supplied.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-26-2008, 07:15 AM Re: Why wont this query work?!
Experienced Talker

Posts: 38
Name: Alan
Trades: 0
Quote:
Originally Posted by dansgalaxy View Post
This is pretty noobish i am sure, but bit late and everyone i know which would know is offline lol so thought might get a faster answer here

And yes i know this is SQL, but i think its more likely the PHP in which might be the problem.

I have two SQL query strings one works the other dont but i cant see why =/

PHP Code:
$result "INSERT INTO `stats` stream_status='".$streamstatus."', listen='".$currentlisteners."', 
time='"
.date('Y-m-d H:i:s')."', listen_peak='".$peaklisteners."', unique_listen='".$reportedlisteners."'";
$result2 'INSERT INTO `stats` (`id`,`stream_status`,`listen`,`unique_listen`,`listen_peak`,`time`) VALUES (NULL,"'.$streamstatus.'","'.$currentlisteners.'","'.$reportedlisteners.'","'.$peaklisteners.'","'.date('Y-m-d H:i:s').'");'
$result2 works, but $result doesnt

I much prefer the $result style and want the query to be in that format but can seem to do that and make it work

can someone please advise.

TP for good answers as always!

Dan
Your first query is way off base! You don't specify fields that way. You don't treat database field names the same as you would your script variables. It should be like the second one but really, get rid of all those extra quotes and cocantations! Like this:

PHP Code:
$result2 "INSERT INTO `stats` (`id`,`stream_status`,`listen`,`unique_listen`,`listen_peak`,`time`) VALUES (NULL,'$streamstatus','$currentlisteners','$reportedlisteners','$peaklisteners','date(Y-m-d H:i:s)'"
That should work just fine for you.
__________________

Please login or register to view this content. Registration is FREE

Last edited by alhefner; 10-26-2008 at 07:17 AM.. Reason: TYPO
alhefner is offline
Reply With Quote
View Public Profile Visit alhefner's homepage!
 
Old 10-26-2008, 09:57 AM Re: Why wont this query work?!
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
hmm.... ookay

well i have always used the format of
PHP Code:
$result "INSERT INTO stats stream_status='$streamstatus', listen='$currentlisteners', 
time='date('Y-m-d H:i:s')', listen_peak='
$peaklisteners', unique_listen='$reportedlisteners'"
for all my queries as i find its the cleanest way which helps to prevent me messing it up

and this style is working for all my other scripts and queries which is why i am a little puzzled. =/

DO'H Do'h do'h

just found what was wrong!!!

SET

the query should read
PHP Code:
"INSERT INTO stats SET stream_status='$streamstatus', listen='$currentlisteners', 
time='"
.date('Y-m-d H:i:s')."', listen_peak='$peaklisteners', unique_listen='$reportedlisteners'" 
silly me

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-26-2008, 10:54 AM Re: Why wont this query work?!
Joshy D's Avatar
Extreme Talker

Posts: 178
Name: Josh
Trades: 0
yes, silly you dan :|
__________________
Personal UK Webhosting

Please login or register to view this content. Registration is FREE
Joshy D is offline
Reply With Quote
View Public Profile
 
Old 10-26-2008, 12:09 PM Re: Why wont this query work?!
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Lol...

Josh... do i need to go into the back catelogue of joshy d's stupidity o.O

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Why wont this query work?!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.35034 seconds with 12 queries