1

I'm trying to run a php file and I get two warnings, which I can't seem to place. The warnings:

  • PHP Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line 0

  • PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /etc/baseconetrial2.php on line 19

The code:

<?php


//connectie database


mysql_connect('localhost','heregoestheusername','heregoesthepass');

@mysql_select_db('admin_subscriptions') or die( "Unable to select database");


$type = "proefabonnement";


$checksql = "SELECT * FROM subscriptions where (type_abonnement = '$type' AND  DATE(timestamp) = DATE_SUB( CURDATE( ) , INTERVAL 26))";

$checkresult = mysql_query($checksql);

while ($check = mysql_fetch_array($checkresult)) {





$mail_ontv = "[email protected]"; 

$_POST['onderwerp'] = "Verlopen Trial Account";

    // set datum 
    $datum = date("d.m.Y H:i"); 

    // set ip 
    $ip = $_SERVER['REMOTE_ADDR']; 

    $inhoud_mail .= $_SERVER['SCRIPT_URI'] . "\n\n";

    $inhoud_mail .= "Binnenkort verloopt er een trail account!\n\n\n";  
    $inhoud_mail .= "Bedrijfsnaam: " . $check['bedrijfsnaam'] . "\n\n"; 
    $inhoud_mail .= "Telefoonnummer: " . $check['telefoonnummer'] . "\n\n"; 
    $inhoud_mail .= "E-mail adres: " . $check['email'] . "\n\n"; 
    $inhoud_mail .= "Telefoonnummer contactpersoon: " . $check['telefoonnummercontact'] . "\n\n"; 
    $inhoud_mail .= "E-mail adres contactpersoon: " . $check['emailcontact'] . "\n\n"; 
    $inhoud_mail .= "Hieronder de link voor de klant:\n\n\n";
    $inhoud_mail .= "http://www.basecone.nl/upgrade1?key=".$check['unique']."\n\n"; 

    $inhoud_mail .= "Verstuurd op " . $datum . " via het ip " . $ip . "\n\n"; 

    $headers = "From: BaseconeWizard < [email protected] >";

    $headers = stripslashes($headers);
    $headers = str_replace("\n", "", $headers); // Verwijder \n 
    $headers = str_replace("\r", "", $headers); // Verwijder \r 
    $headers = str_replace("\"", "\\\"", str_replace("\\", "\\\\", $headers)); // Slashes van quotes 



    $_POST['onderwerp'] = str_replace("\n", "", $_POST['onderwerp']); // Verwijder \n 
    $_POST['onderwerp'] = str_replace("\r", "", $_POST['onderwerp']); // Verwijder \r 
    $_POST['onderwerp'] = str_replace("\"", "\\\"", str_replace("\\", "\\\\", $_POST['onderwerp'])); // Slashes van quotes 

    mail($mail_ontv, $_POST['onderwerp'], $inhoud_mail, $headers); 







}


?>

Thanks guys!

2

3 Answers 3

3

PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /etc/baseconetrial2.php on line 19

$checksql = "SELECT * FROM subscriptions where (type_abonnement = '$type' AND  DATE(timestamp) = DATE_SUB( CURDATE( ) , INTERVAL 26 DAY))";

note the DAY parametre of DATE_SUB mysql function

I would also suggest to use mysql_real_escape_string() function to sanitize the "$type" variable

Sign up to request clarification or add additional context in comments.

5 Comments

I do understand your real_escape remark, though it's not clear to me what you mean by the other? 'note the DAY parametre of DATE_SUB mysql function'?
Hi hd1 i believe that what i wrote above is an answer to the problem (the fetch_array warning). There is an error in the mysql query causing mysql_query return "false" instead of resource. Fixing that will get rid of the warning.
Hi, Your SQL command goes like: .... DATE_SUB( CURDATE( ) , INTERVAL 26)) DATE_SUB function requires one more parametre - to say what the 26 is OF - eg. DAY, HOUR, MINUTE ...
Seriously? I didn't know that, do I place it before or after the number? DAY 26, or 26 DAY? Thanks!
Never mind, some Google-ing gave me the answer! And you put it in your own code I see. Thanks a lot!
2

Some part of your code or your host is using safe_mode which has been deprecated.

The PHP safe mode is an attempt to solve the shared-server security problem. It is architecturally incorrect to try to solve this problem at the PHP level, but since the alternatives at the web server and OS levels aren't very realistic, many people, especially ISP's, use safe mode for now.

Please do not use @ to suppress errors. Use error handlers or enable full error reporting.

mysql_fetch_array() expects parameter 1 to be resource

Your query failed and is thus passing a boolean result to mysql_fetch_array. But since you're not catching errors, you won't know.

$checkresult = mysql_query($checksql) or die(mysql_error());

3 Comments

I deleted the '@' and added the last line of code you suggested. Which part of my code is using the safe_mode so I can alter it?
@user1555076 Where is your PHP instance? On a host or locally? If local, you can edit your php.ini.
It's locally, I'll go and search for the PHP.ini. Thanks!
2

for

PHP Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line 0

Remove or comment

safe_mode = "On/Off" from your php.ini

For PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /etc/baseconetrial2.php on line 19

Please Use

if (!$checksql) die(mysql_error()); 

it will show the problem in query

1 Comment

Thanks, going to give this a try!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.