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 = 'myemail@email.com';


?>

Link to comment
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 = 'myemail@email.com';
  } // you can handle a no results found error here.
} // you can handle a query failed error here.

?>

Link to comment
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.

 

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

 

Thanks!

 

 

Link to comment
Share on other sites

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.