hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Having a bit of trouble with this code:
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Having a bit of trouble with this code:

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 02-21-2004, 03:46 PM
Mark226 Mark226 is offline
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:
Warningmysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/livoniag/public_html/eclubcron.php on line 11 

Reply With Quote


Sponsored Links
  #2  
Old 02-21-2004, 04:40 PM
mpdaddy mpdaddy is offline
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

Reply With Quote
  #3  
Old 02-21-2004, 04:54 PM
Mark226 Mark226 is offline
Web Hosting Master
 
Join Date: Jul 2003
Posts: 632
No, still error Same one.

Reply With Quote
Sponsored Links
  #4  
Old 02-21-2004, 05:20 PM
mpdaddy mpdaddy is offline
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.

Reply With Quote
  #5  
Old 02-21-2004, 11:00 PM
W-S-Nexus W-S-Nexus is offline
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

Reply With Quote
  #6  
Old 02-22-2004, 02:07 AM
Mark226 Mark226 is offline
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?

Reply With Quote
  #7  
Old 02-22-2004, 02:29 AM
MGCJerry MGCJerry is offline
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.

Reply With Quote
  #8  
Old 02-22-2004, 02:30 AM
digitok digitok is offline
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

Reply With Quote
  #9  
Old 02-22-2004, 02:34 AM
Mark226 Mark226 is offline
Web Hosting Master
 
Join Date: Jul 2003
Posts: 632
Added comas and apostraphies as you noted. Same error:

PHP Code:
Warningmysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/livoniag/public_html/eclubcron.php on line 11 

Reply With Quote
  #10  
Old 02-22-2004, 03:57 AM
mg- mg- is offline
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.

Reply With Quote
  #11  
Old 02-22-2004, 06:08 AM
Burhan Burhan is offline
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

Reply With Quote
  #12  
Old 02-22-2004, 06:12 AM
mg- mg- is offline
VP Of Twinkies
 
Join Date: Jan 2004
Location: Vancouver, BC
Posts: 984
I can't believe I didn't notice that o.O

Reply With Quote
  #13  
Old 02-22-2004, 07:45 PM
Mark226 Mark226 is offline
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:
Warningmysql_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!

Reply With Quote
  #14  
Old 02-22-2004, 08:10 PM
Mark226 Mark226 is offline
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

Reply With Quote
  #15  
Old 02-22-2004, 08:25 PM
Mark226 Mark226 is offline
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.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Cloud Industry Forum Establishes Cloud Service Provider Code of Practice Web Hosting News 2012-09-21 12:38:23
DigiCert Launches Extended Validation Code Signing Certificates Web Hosting News 2012-08-15 15:30:28
Non-Profit New Zealand Computer Society to Develop Cloud Code of Practice Web Hosting News 2011-09-02 17:22:36
SSL Certificate Authority Comodo Providing Intel Application Certification Web Hosting News 2011-08-12 15:51:28
Web Host DreamHost Contributing Code for Ceph File System to OpenStack Web Hosting News 2011-06-23 20:40:32


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?