Jump to content

Simple Script Error, Help Pls


stevens

Recommended Posts

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:
[quote]PHP Warning:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /2.php on line 9[/quote]

Code:
[quote]<?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";
}
?>
[/quote]
Link to comment
https://forums.phpfreaks.com/topic/16803-simple-script-error-help-pls/
Share on other sites

[quote author=spfoonnewb link=topic=103293.msg411262#msg411262 date=1154963079]
[quote]SELECT * FROM details [/quote]
[/quote]
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:
[code]$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());[/code]
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.

[size=18pt][color=red][b]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[/b][/color][/size]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.