Why wont this query work?!
10-25-2008, 10:16 PM
|
Why wont this query work?!
|
Posts: 6,521
Name: Dan
Location: Swindon
|
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 <<
|
|
|
|
10-26-2008, 03:37 AM
|
Re: Why wont this query work?!
|
Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
|
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?
|
|
|
|
10-26-2008, 07:15 AM
|
Re: Why wont this query work?!
|
Posts: 38
Name: Alan
|
Quote:
Originally Posted by dansgalaxy
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.
Last edited by alhefner; 10-26-2008 at 07:17 AM..
Reason: TYPO
|
|
|
|
10-26-2008, 09:57 AM
|
Re: Why wont this query work?!
|
Posts: 6,521
Name: Dan
Location: Swindon
|
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 <<
|
|
|
|
10-26-2008, 10:54 AM
|
Re: Why wont this query work?!
|
Posts: 178
Name: Josh
|
yes, silly you dan :|
__________________
Personal UK Webhosting
|
|
|
|
10-26-2008, 12:09 PM
|
Re: Why wont this query work?!
|
Posts: 6,521
Name: Dan
Location: Swindon
|
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 <<
|
|
|
|
|
« Reply to Why wont this query work?!
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|