Kane250 Posted May 28, 2008 Share Posted May 28, 2008 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'; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted May 28, 2008 Share Posted May 28, 2008 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. ?> Quote Link to comment Share on other sites More sharing options...
Kane250 Posted May 28, 2008 Author Share Posted May 28, 2008 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.