
02-21-2004, 03:46 PM
|
|
Web Hosting Master
|
|
Join Date: Jul 2003
Posts: 632
|
|
Having a bit of trouble with this code:
Two things, one, there is an error. Secondly, I am trying to make it dispatch an email to every row in the database who's birthday is today. Could someone help with this? I know how to use the mail(); function, and I have already set up the query to find rows where today is their brithday. Just not sure what to do next.
PHP Code:
<?
$todaymonth = date(n);
$todayday = date(j);
$dbcnx = mysql_connect("localhost", "username", "passwrd");
mysql_select_db("database");
$result = "SELECT FirstName LastName Email BirthMonth BirthDay FROM eclub WHERE BirthMonth=$todaymonth AND BirthDay=$todayday";
while ($row = mysql_fetch_array($result)) {
echo("<p>" . $row["Email"] . "</p>");
}
?>
The error:
PHP Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/livoniag/public_html/eclubcron.php on line 11
|

02-21-2004, 04:40 PM
|
|
Temporarily Suspended
|
|
Join Date: Feb 2004
Location: Minneapolis, MN
Posts: 5
|
|
change this part
$result = "SELECT FirstName LastName Email BirthMonth BirthDay FROM eclub WHERE BirthMonth=$todaymonth AND BirthDay=$todayday";
to
$result = mysql_query ("SELECT FirstName LastName Email BirthMonth BirthDay FROM eclub WHERE BirthMonth=$todaymonth AND BirthDay=$todayday");
See if that gets you anywhere
Regards
Wayne
|

02-21-2004, 04:54 PM
|
|
Web Hosting Master
|
|
Join Date: Jul 2003
Posts: 632
|
|
No, still error  Same one.
|

02-21-2004, 05:20 PM
|
|
Temporarily Suspended
|
|
Join Date: Feb 2004
Location: Minneapolis, MN
Posts: 5
|
|
PHP Code:
<?
$todaymonth = date(n);
$todayday = date(j);
$dbcnx = mysql_connect("localhost", "username", "passwrd");
mysql_select_db("database");
$result = mysql_query ("SELECT FirstName LastName Email BirthMonth BirthDay FROM eclub WHERE BirthMonth=$todaymonth AND BirthDay=$todayday");
var_dump (mysql_fetch_array ($result));
echo("<p>" . $result["Email"] . "</p>");
?>
I am pretty new to php, but hopefully this will get you somewhere. Looks logical to me.
|

02-21-2004, 11:00 PM
|
|
Newbie
|
|
Join Date: Aug 2003
Location: Barrie, ON, Canada
Posts: 6
|
|
Try adding(or die("[ Operation type ] : " . mysql_error())  to each mysql command... Put in your own Operation type for each die portion.... Should tell you where the error is occuring....
The error could be in the connection line, the select database line, or with the query itself..
cheers
Richard
|

02-22-2004, 02:07 AM
|
|
Web Hosting Master
|
|
Join Date: Jul 2003
Posts: 632
|
|
Ok, I did that, and the error is "Query Empty" for Line 11.
However, it should not be. I added a row in which the birthday is today's date (2/22). The query doesn't seem to find this row as a match. Any idea why?
|

02-22-2004, 02:29 AM
|
|
Web Hosting Master
|
|
Join Date: Jan 2002
Posts: 2,998
|
|
Try this:
PHP Code:
$result = "SELECT FirstName, LastName, Email, BirthMonth, BirthDay FROM eclub WHERE BirthMonth='$todaymonth' AND BirthDay='$todayday'";
Edit:
Note the single quotes. I notice many times this is the only way I can execute queries like this, so this is usually how I do it. I also heard it is a good start to help prevent SQL inection (not sure if true though).
I also just noticed there are no commas.
Edit2:
Looks like digitok posted when I was doing my first edit 
__________________
Don't like what I say? Ignore me because it will be the only way you can shut me up.
|

02-22-2004, 02:30 AM
|
|
Web Hosting Master
|
|
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
|
|
You do not have any commas seperating the fields you wish to extract from the table.
You cannot just go
SELECT blah blah2 FROM table
It must be in the format
SELECT blah,blah2 FROM table
__________________
nu-metal.org :: coming soon
|

02-22-2004, 02:34 AM
|
|
Web Hosting Master
|
|
Join Date: Jul 2003
Posts: 632
|
|
Added comas and apostraphies as you noted. Same error:
PHP Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/livoniag/public_html/eclubcron.php on line 11
|

02-22-2004, 03:57 AM
|
|
VP Of Twinkies
|
|
Join Date: Jan 2004
Location: Vancouver, BC
Posts: 984
|
|
did you check to make sure the tables you're requesting.. exist?
put quotes around the date("j"); stuff.
|

02-22-2004, 06:08 AM
|
|
Community Guide
|
|
Join Date: Jul 2003
Location: Kuwait
Posts: 5,100
|
|
You need to do mysql_query() before you can fetch anything.
mysql_fetch_array() expects a MySQL result resource type, which is only returned by mysql_query().
In other words, in your script, you are asking for results when you haven't exectued the query.
You also need to use mysql_error() after you execute the query, don't assume it worked. Also, echo out your query before you execute it.
Re-paste your edited code again if you still have problems.
__________________
In order to understand recursion, one must first understand recursion.
If you feel like it, you can read my blog
Signal > Noise
|

02-22-2004, 06:12 AM
|
|
VP Of Twinkies
|
|
Join Date: Jan 2004
Location: Vancouver, BC
Posts: 984
|
|
I can't believe I didn't notice that o.O
|

02-22-2004, 07:45 PM
|
|
Web Hosting Master
|
|
Join Date: Jul 2003
Posts: 632
|
|
Ok, this is very strange. I fixed the problem in the original script. Now I'm having the SAME problem in a new script:
PHP Code:
<?
$dbcnx = mysql_connect("localhost", "username", "password");
mysql_select_db("database");
$result = @mysql_query("SELECT WorkPhone FROM 2003");
if (!result) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
while ($row = mysql_fetch_array($result)) {
echo("<p>" . $row["WorkPhone"] . "</p>");
}
?>
Error:
PHP Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/swiftglo/public_html/fixdb.php on line 12
If you need me to put that "debugging" code in there, could you specify what/where? Thanks!
|

02-22-2004, 08:10 PM
|
|
Web Hosting Master
|
|
Join Date: Jul 2003
Posts: 632
|
|
Update: Added extra debugging to the query, got this:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '2003' at line 1
|

02-22-2004, 08:25 PM
|
|
Web Hosting Master
|
|
Join Date: Jul 2003
Posts: 632
|
|
Ok, this is bullcrap. I figured it out, but listen to this... you will be amused.
SINCE the table name is all numbers (2003), the query does not work without writing `2003`. You would think they are APOSTRAPHE's... but they're not. It's the key next to the 1 key. Took me a good hour or so to figure that out. Only way I noticed it is because phpMyAdmin has a default query typed in when you go to the SQL tab, and I saw thsoe.
Thanks anyway for those who tried to look at this code for me.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
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
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|