Jump to content


Photo

Simple Script Error, Help Pls


  • Please log in to reply
5 replies to this topic

#1 stevens

stevens
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 07 August 2006 - 02:45 PM

Hi I am running the script below and it works perfectly (updates the database ok) yet displays the following error, please help me undertsand why. Thankyou.

(The code is to be run by a cron job to check whether an account has expired)

Error Message:

PHP Warning:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /2.php on line 9


Code:

<?php

include("config.php");

$connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!");
$query = "SELECT * FROM details WHERE order_no != 0";
$result = mysql_db_query($db, $query, $connection) or die ("Could not execute query: $query. " . mysql_error());

while ($newArray = mysql_fetch_assoc($result)) {

     $order_no = $newArray['order_no'];
$word = $newArray['word'];
     $email = $newArray['cust_email'];
    $start_date = $newArray['start_date'];
$end_date = $newArray['end_date'];

$date = date("Y-m-d");

if ($end_date == $date) {

$query = "DO QUERY";

$result = mysql_db_query($db, $query, $connection) or die ("Could not execute query: $query. " . mysql_error());

    $subject = "YOUR ACCOUNT HAS NOW EXPIRED";
$msg = "THE ACCOUNT YOU HAVE PURCHASED ON ".$domain." HAS NOW EXPIRED\n\n";
    mail($email, $subject, $msg, "From: ".$orderemail);
}
else {

$days_left = (strtotime($end_date) - strtotime(date("Y-m-d"))) / (60 * 60 * 24);

if ($days_left == '30') {

    $subject = "YOUR ACCOUNT IS EXPIRING IN 30 DAYS";
$msg = "THE ACCOUNT YOU HAVE PURCHASED ON ".$domain." IS EXPIRING IN 30 DAYS\n\n";
    $msg.= "PLEASE LOGIN TO YOUR MEMBERS ACCOUNT NOW\n\n";
    mail($email, $subject, $msg, "From: ".$orderemail);
}
}
echo "$days_left";
}
?>


I wish i'd have thought up www.500wordsite.com !

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 07 August 2006 - 02:47 PM

Change mysql_db_query to mysql_query and then select a database right after connecting.

#3 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 07 August 2006 - 02:47 PM

I dont see you selecting a database.

Orio.
Think you're smarty?

(Gone until 20 to November)

#4 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 07 August 2006 - 03:04 PM

SELECT * FROM details



#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 August 2006 - 03:10 PM

SELECT * FROM details


Thats not what orio ment,m that code doesnt select the database but queries the details table. He ment selecting mysql database using mysql_select_db('dbname_here');

stevens I'd suggest you use:
$connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!");
mysql_select_db($db, $connection);
$query = "SELECT * FROM details WHERE order_no != 0";
$result = mysql_query($query, $connection) or die ("Could not execute query: $query. " . mysql_error());


#6 stevens

stevens
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 07 August 2006 - 09:03 PM

Hi everyone and thanks for your help, Unfortunatly none of your answers worked.

My database is being called in the config.php for you who were not sure.

@wildteen I changed my code to what you posted but still got the same error - Isnt the code you posted the same as what i already had? thanks anyway.

EDIT: I HAVE SORTED IT NOW, I FOUND THE ERROR. THE ERROR WAS THE SECOND QUERY & RESULT NAME. I CHANGED IT TO QUERY2 & RESULT2 AND NO ERRORS  ;D THANKS AGAIN FOR YOUR HELP GUYS
I wish i'd have thought up www.500wordsite.com !




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users