Jump to content

[SOLVED] Changes for php5?


Kane250

Recommended Posts

I was using the following code on a server with php4 and everything worked great. I am now using the code on a new server with php5 and I am getting these error messages:

 

-Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in index.php on line 37

-Warning: implode() [function.implode]: Bad arguments. in index.php on line 41

 

Can someone take a look and tell me what I need to change so this is compatible with php5? I'm basically pulling email addresses from a table and putting them together seperated by commas.

 

Thanks!

 

<php
$mlistcontacts = mysql_query('SELECT email FROM emaillist');

while($mlistcontacts2 = mysql_fetch_assoc($mlistcontacts)){
$massmail[] = $mlistcontacts2['email'];
}
//TAKE THE ARRAY AND GLUE THE ROWS TOGETHER WITH COMMAS, & CREATE HEADERS FOR THE E-MAIL
$to =  implode(",", $massmail);
$subject = $_POST['subject'];
$message = stripslashes ($_POST['msgpost']);
$from = '[email protected]';


?>

Link to comment
https://forums.phpfreaks.com/topic/107583-solved-changes-for-php5/
Share on other sites

These warnings (not errors) are simply because you are failing to check your queries succeed and return results as well as records. Nothing to do with changes in php versions (your error reporting level is likely set lower in php4), just poor coding practicees.

 

<?php

if ($mlistcontacts = mysql_query('SELECT email FROM emaillist')) {
  if (mysql_num_rows($mlistcontacts)) {
    while ($mlistcontacts2 = mysql_fetch_assoc($mlistcontacts)){
      $massmail[] = $mlistcontacts2['email'];
    }
    //TAKE THE ARRAY AND GLUE THE ROWS TOGETHER WITH COMMAS, & CREATE HEADERS FOR THE E-MAIL
    $to =  implode(",", $massmail);
    $subject = $_POST['subject'];
    $message = stripslashes ($_POST['msgpost']);
    $from = '[email protected]';
  } // you can handle a no results found error here.
} // you can handle a query failed error here.

?>

These warnings (not errors) are simply because you are failing to check your queries succeed and return results as well as records. Nothing to do with changes in php versions (your error reporting level is likely set lower in php4), just poor coding practicees.

 

Oh I see what you mean...thanks. I'm still fairly new to php and learning more as I go.

 

Thanks!

 

 

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.