Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Error

Status
Not open for further replies.

astrodestino

IS-IT--Management
Feb 19, 2005
179
AR
Hi!
I got mys site which is running ok at my localhost.
I upload it and when I want to access it will return:

SELECT * FROM horoscopo where dia=09 and mes=12 and ano=2005 order by id asc limit 0,30 query failed.

The database, username and password are ok cause if I change anyone os those I will get username or password error.

I go to phpmyadmin and I copy & pasto the sql syntax and it will return all the results.

Here is my code:
Code:
function stamp2date($stamp){        // expects a valid timestamp
   return date("m.d.Y", $stamp);    // returns 19.11.2005
}
$hoy       = mktime(0, 0, 0, date("m")  , date("d"), date("Y"));
list($month, $day, $year) = split('[/.-]', stamp2date($hoy));
$sqlstm="SELECT * FROM horoscopo where dia=".$day." and mes=".$month." and ano=".$year." 

order by id asc limit 0,30";
$link = mysql_connect('localhost', 'username', 'pass') or die("Could not 

connect1");
mysql_select_db('mydb', $link);// or die("Could not select".'adhoro');
$result = mysql_query($sqlstm, $link) or die("Query failed1".$sqlstm);

Its strange, in phpmyadmin (online) and in my localhost I got no problems, my problems are online :(

How can this be fixed?
Tnx!
 
You have problems with your SELECT query syntax. Replace it with this:

Code:
$sqlstm = "select * from horoscopo
           where dia ='$day'
           and mes = '$month'
           and ano = '$year'
           order by id asc
           limit 30";
 
Are you storing your date in your database as an actual date field or a varchar field? Store it as a date, eliminate all the extra work and just select your date where it matches the required date.

Instead of this:
return date("m.d.Y", $stamp); // returns 19.11.2005

Use this:
return date("Y.m.d", $stamp); // returns 2005.11.19

You can now compare that date directly with a date field within your database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top