Jump to content

Recommended Posts

I have a table that is set up with two fields. id int(5) auto_increment primary_key and time int(11) NOT NULL. My insert query inserts the time() into the time field. this works right. When I try and retrieve this number and add 60 to it my result is only 60. I get a not a valid resource on this mysql_fetch_array(). When I get the number for the time field is it treated as an int or something else?

 

This is part of my code:

mysql_connect($host, $user, $pass);
mysql_select_db($database) or die(mysql_error());
//I want to find the last entry of time in my $table
$sql = "SELECT * FROM $table WHERE id ORDER BY id DESC LIMIT 1";
$info = mysql_fetch_array($sql[time]);
//creates a new variable to compare with last time entry of $table
//(+ 60 will be changed to equal 1 week once the script is working)
$result = ($info + 60);
$newdate = time();
//I am trying to compair my two times and if $newdate
if ($newdate < $result){
exit();
}else{

 

These are my warnings:

Notice: Use of undefined constant time - assumed 'time' in /home/xxxxxx/public_html/mailer.php on line 15

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/xxxxxx/public_html/mailer.php on line 15

 

Line 15 is the mysql_fetch_array()

Can someone help me with this?

Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/163147-solved-simple-query-question/
Share on other sites

OK I don't remember taking it out but I guess I did. Here is the new code with a query:

[php}//sets date in seconds to be inserted into Db till next cron job runs
$date = time();
mysql_connect($host, $user, $pass);
mysql_select_db($database) or die(mysql_error());
//I want to find the last entry of time in my $table
$sql = mysql_query("SELECT * FROM $table WHERE id ORDER BY id DESC LIMIT 1");
$info = mysql_fetch_array($sql[time]);
//creates a new variable to compare with last time entry of $table
//(+ 60 will be changed to equal 1 week once the script is working)
$result = ($info + 60);
$newdate = time();
//I am trying to compair my two times and if $newdate
if ($newdate < $result){
exit();
}else{[/code]

 

I am still getting the same errors.

 

Notice: Use of undefined constant time - assumed 'time' in /home/xxxxxx/public_html/mailer.php on line 15

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/xxxxxx/public_html/mailer.php on line 15

 

I was wrote the mail() last night to be run by a cron job and it worked great. Only problem someone else opened it three times in the next hour. I figure it was search engines so I creted a DB and table with id int(5) auto_increment primary_key and time int(11) and I wanted to select the time field as an int and and wanted to compare a new time int and compare both. If less the script should exit else run mail(). I am hoping to make it only run once a week.

I guess I will try again.

//sets date in seconds to be inserted into Db till next cron job runs
$date = time();
mysql_connect($host, $user, $pass);
mysql_select_db($database) or die(mysql_error());
//I want to find the last entry of time in my $table
$sql = mysql_query("SELECT time FROM $table ORDER BY id DESC LIMIT 1;");
$info = mysql_fetch_array($sql[1]);
//creates a new variable to compare with last time entry of $table
//(+ 60 will be changed to equal 1 week once the script is working)
$result = ($info+ 60);
$newdate = time();
$count = ($newdate < $result);
//I am trying to compare my two times and if $newdate
if (!$count){
exit();
}else{

Sorry about the mistype.

No thank you. The topic is solved now. I have so much to learn. I need to learn to pay attention to detail more that anything. Here is the code:

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
$host = "localhost";
$user = "user";
$pass = "password";
$table = "mailer";
$database = "mailer";
//sets date in seconds to be inserted into Db till next cron job runs
$date = time();
mysql_connect($host, $user, $pass);
mysql_select_db($database) or die(mysql_error());
//I want to find the last entry of time in my $table
$sql = mysql_query("SELECT time FROM $table ORDER BY id DESC LIMIT 1;");
$info = mysql_fetch_array($sql);
//creates a new variable to compare with last time entry of $table
//(+ 60 will be changed to equal 1 week once the script is working)
//be sure and use single quotes inside your array square brackets
$result = ($info['time'] + 60);
$newdate = time();
//I am trying to compare my two times and if $newdate
if ($newdate < $result){
exit();
}else{
$to = "jmr3460@abc.net";
$subject = "Upcoming Events";
$upcoming = "Upcoming Events for the Calendar \n\nhttp://www.xxxxxx.org/activities\n
If you can click this link or you may have \nto copy and paste the above line into your browser address bar.";
$headers = "From: calendar-admin@xxxxxx.org";
mail($to,$subject,$upcoming,$headers);
mysql_query("INSERT INTO $table VALUES('id','$date')") or die(mysql_error());
}
?>
<html><body>
<?php
	echo $newdate . "<br />";
	echo $result;
?>
</body></html>

This script was written to send out a reminder once a week to a group of people with a link on it that will lead them to upcoming events for an event calendar. I first built the mailer thinking that all was good and set my cron job to open it once a week then within an hour I got three emails.(I figure search engines) so I had to add an exit function so it would not be allowed to be sent out more that one week from the last opening. I created a Database and table with id auto_increment primary key and a time field that inserted seconds as int. When the script is called the script is supposed to add 604800 to the last entry and compare them with the current time in seconds. If less than then the script will exit() else the mail() will fly. I am grateful for the help I got though. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.