db query not working as expected

This is a discussion on db query not working as expected within the PHP General forums, part of the PHP Programming Forums category; I have this code: mysql_connect ($local_host, $local_user, $local_pass); mysql_select_db ($local_db); mysql_query ("DELETE FROM tmphitsmag"); $result = mysql_query ("SELECT ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-07-2007
Ed Curtis
 
Posts: n/a
Default db query not working as expected

I have this code:

mysql_connect ($local_host, $local_user, $local_pass);
mysql_select_db ($local_db);

mysql_query ("DELETE FROM tmphitsmag");

$result = mysql_query ("SELECT DISTINCT company FROM view_log WHERE
company != ''");

if ($row = mysql_fetch_array($result)) {

do {

$magazine_path = $row['company'];
$magazine_path = explode("/", $magazine_path);

echo str_replace("_", " ", $magazine_path[2]) . "<br>";

mysql_query ("INSERT INTO tmphitsmag (magazine)
VALUES ('$magazine_path[2]')");

} while($row = mysql_fetch_array($result));

} mysql_close();

The code dumps the first table fine, selects, manipulates, and echoes
the string the way I expect, but fails to input the string into the
tmphitsmag table.

Any ideas?

Thanks,

Ed
Reply With Quote
  #2 (permalink)  
Old 03-07-2007
Tijnema !
 
Posts: n/a
Default Re: [PHP] db query not working as expected

On 3/7/07, Ed Curtis <e_curtis@homes2see.com> wrote:
>
> I have this code:
>
> mysql_connect ($local_host, $local_user, $local_pass);
> mysql_select_db ($local_db);
>
> mysql_query ("DELETE FROM tmphitsmag");
>
> $result = mysql_query ("SELECT DISTINCT company FROM view_log WHERE
> company != ''");
>
> if ($row = mysql_fetch_array($result)) {
>
> do {
>
> $magazine_path = $row['company'];
> $magazine_path = explode("/", $magazine_path);
>
> echo str_replace("_", " ", $magazine_path[2]) . "<br>";
>
> mysql_query ("INSERT INTO tmphitsmag (magazine)
> VALUES ('$magazine_path[2]')");



Not sure about it but try this:
mysql_query ("INSERT INTO tmphitsmag (magazine) VALUES
('".$magazine_path[2]."')");

Tijnema

} while($row = mysql_fetch_array($result));
>
> } mysql_close();
>
> The code dumps the first table fine, selects, manipulates, and echoes
> the string the way I expect, but fails to input the string into the
> tmphitsmag table.
>
> Any ideas?
>
> Thanks,
>
> Ed
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Reply With Quote
  #3 (permalink)  
Old 03-07-2007
Tijnema !
 
Posts: n/a
Default Re: [PHP] db query not working as expected

On 3/7/07, Ed Curtis <e_curtis@homes2see.com> wrote:
>
> I have this code:
>
> mysql_connect ($local_host, $local_user, $local_pass);
> mysql_select_db ($local_db);
>
> mysql_query ("DELETE FROM tmphitsmag");
>
> $result = mysql_query ("SELECT DISTINCT company FROM view_log WHERE
> company != ''");
>
> if ($row = mysql_fetch_array($result)) {
>
> do {
>
> $magazine_path = $row['company'];
> $magazine_path = explode("/", $magazine_path);
>
> echo str_replace("_", " ", $magazine_path[2]) . "<br>";
>
> mysql_query ("INSERT INTO tmphitsmag (magazine)
> VALUES ('$magazine_path[2]')");




what about adding the usual "or die"?
mysql_query ("INSERT INTO tmphitsmag (magazine)VALUES
('$magazine_path[2]')") or die(mysql_error());

Tijnema

} while($row = mysql_fetch_array($result));
>
> } mysql_close();
>
> The code dumps the first table fine, selects, manipulates, and echoes
> the string the way I expect, but fails to input the string into the
> tmphitsmag table.
>
> Any ideas?
>
> Thanks,
>
> Ed
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Reply With Quote
  #4 (permalink)  
Old 03-07-2007
cajbecu
 
Posts: n/a
Default Re: [PHP] db query not working as expected

try:

mysql_query ("INSERT INTO tmphitsmag (magazine) VALUES
('{$magazine_path[2]}')");

cajb.
Reply With Quote
  #5 (permalink)  
Old 03-07-2007
Stut
 
Posts: n/a
Default Re: [PHP] db query not working as expected

Ed Curtis wrote:
> mysql_query ("INSERT INTO tmphitsmag (magazine)
> VALUES ('$magazine_path[2]')");


Replace that with this...


mysql_query ("INSERT INTO tmphitsmag (magazine) VALUES

('".mysql_real_escape_string($magazine_path[2])."')");

-Stut
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:17 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0