Re: [PHP] db query not working



I saw two people pointing two errors on the SQL insert statement which you would have found yourself had you put the 'or die()' at the end of the query, as someone else suggested. Do never leave any query without the 'or die()' after it (or any other means to check if mysql_query returns anything not false). This would have saved lots of your time, our time, everybody's bandwidth and would avoid your asking everybody again for the next error you make. We all make errors, none of us is above that, that's why, at least in my case, I never fail to add the or die() at the end. That's why the developers of function libraries have put some means of reporting errors back. It takes time for providing good error reporting. You are wasting that effort as well.

Do you deserve all this speech? No more than the dozens who write what I call 'ballistic' code: code you have no control over once it launches. Guided missiles are far better. Anyway, you got it because I had time to rant about this.

Satyam



----- Original Message ----- From: "Ed Curtis" <e_curtis@xxxxxxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Wednesday, March 07, 2007 3:28 PM
Subject: [PHP] db query not working


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();

It dumps the table fine, works the explode, outputs the string in the echo command the way I expect, but doesn't place the value in tmphitsmag table.

Anyone have a clue?

Thanks,

Ed

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.7/712 - Release Date: 06/03/2007 15:42


.



Relevant Pages

  • Re: [PHP] array issues
    ... I think you ment ... are doing, but with only the query to look at, it's hard to tell... ... I have paste a sample record below; ... PHP General Mailing List ...
    (php.general)
  • RE: [PHP] mysql update query
    ... populated from a monthly csv file supplied from an external source. ... Subject: mysql update query ... PHP General Mailing List ...
    (php.general)
  • Re: [PHP] need help to build a query
    ... you can do "explain $query" to see what MySQL estimates will ... PHP General Mailing List ... To unsubscribe, visit: http://www.php.net/unsub.php ...
    (php.general)
  • Re: [PHP] why so slow?
    ... I have fixed my html and include ... could you please help me figure out how to change the query in box 4 so that it shows the url only when the link is active? ... to www.squareinch.net and includes the response. ... PHP General Mailing List ...
    (php.general)
  • SELECT DISTINCT FROM SQL SERVER USING C# & ADO.NET
    ... Our test database has duplicate data: ... I want to get a list of distinct company names and the most recent ID ... But the above query does not work as I expect. ...
    (microsoft.public.dotnet.languages.csharp)