Computing.Net > Forums > Web Development > php code caught in a loop

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

php code caught in a loop

Reply to Message Icon

Name: smbotans
Date: October 9, 2008 at 16:31:36 Pacific
OS: linux
CPU/Ram: not sure
Product: not sure
Comment:

hi all,

i have a client whose server has been updated to php 5.2.0-8 and now this script, which is used ot send out a newsletter, has 2 problems:

1. it is caught in a loop whenever it is run and never seems to stop

2. the emails sent out come back to his own email box as undeliverable

can someone who knows php 5.2.0-8 please look at the script and see what is causing all this ... i can do basic php but this is beyond me

some things you might like to know about the server:

- php 5.2.0-8

- mysql Ver 14.12 Distrib 5.0.32, for pc-linux-gnu (i386) using readline 5.0

- Sendmail Path : /usr/sbin/sendmail

==============================
<?php

# Include the DB details
require_once('../../connect_db.php');

$subject = $_POST['subject'];
$messagecontent = $_POST['message'];

echo 'Sending E-mails:</br>';

# Create recordset
$colname_rsInstructors = "1";
$query_rsInstructors = sprintf("SELECT i_email, i_username, i_password FROM instructors;", $colname_rsInstructors);
$rsInstructors = mysql_query($query_rsInstructors, $conn) or die ('Could not connect to database because: ' . mysql_error());
$row_rsInstructors = mysql_fetch_assoc($rsInstructors);
$totalRows_rsInstructors = mysql_num_rows($rsInstructors);

do {
$sql = mysql_query("SELECT i_email, i_password, i_username
FROM instructors;")
or die ('Select failed because: ' . mysql_error());

# Set variables from the record set
$email = $row_rsInstructors['i_email'];
$user = $row_rsInstructors['i_username'];
$password = $row_rsInstructors['i_password'];

$messagefooter = "This E-mail has been sent to you as a registered member of the Driving Lesson Booking
Service<br />
http://www.DLBS.co.uk. <br />
To amend your details you can login at http://www.dlbs.co.uk
with the user name $user and password $password.";

$message = "$messagecontent $messagefooter";

# Send email
# @mail($email, $subject, $message, "From: info@dlbs.co.uk");
@mail($email, $subject, $message,
"From: DLBS.co.uk <newsletter@dlbs.co.uk>\r\nMIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n");


echo'E-mail sent to : '.$email. '
';

} while ($row_rsInstructors = mysql_fetch_assoc($rsInstructors));
echo ' All Emails Sent!</br>';
echo 'Back to Admin Home Page';

?>

=======================================

a huge thank you in advance :-)))))

serge

Keep mentally active.

SEO ANALYSIS Discover what search engines really think of your web site.



Sponsored Link
Ads by Google

Response Number 1
Name: CodyJoyce
Date: October 15, 2008 at 04:28:39 Pacific
Reply:

Hi

I'm sorry but i can't really test this. but here is some amended code that i think should work.

<?php

# Include the DB details
require_once('../../connect_db.php');

$subject = $_POST['subject'];
$messagecontent = $_POST['message'];

echo 'Sending E-mails:</br>';

# Create recordset
$colname_rsInstructors = "1";
$query_rsInstructors = sprintf("SELECT i_email, i_username, i_password FROM instructors;", $colname_rsInstructors);
$rsInstructors = mysql_query($query_rsInstructors, $conn) or die ('Could not connect to database because: ' . mysql_error());
$row_rsInstructors = mysql_fetch_assoc($rsInstructors);
$totalRows_rsInstructors = mysql_num_rows($rsInstructors);
while ($row_rsInstructors = mysql_fetch_assoc($rsInstructors)){
$sql = mysql_query("SELECT i_email, i_password, i_username
FROM instructors;")
or die ('Select failed because: ' . mysql_error());

# Set variables from the record set
$email = $row_rsInstructors['i_email'];
$user = $row_rsInstructors['i_username'];
$password = $row_rsInstructors['i_password'];

$messagefooter = "This E-mail has been sent to you as a registered member of the Driving Lesson Booking
Service<br />
http://www.DLBS.co.uk. <br />
To amend your details you can login at http://www.dlbs.co.uk
with the user name $user and password $password.";

$message = "$messagecontent $messagefooter";

# Send email
# @mail($email, $subject, $message, "From: info@dlbs.co.uk");
@mail($email, $subject, $message,
"From: DLBS.co.uk <newsletter@dlbs.co.uk>\r\nMIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n");


echo'E-mail sent to : '.$email. '
';

}
echo ' All Emails Sent!</br>';
echo 'Back to Admin Home Page';

?>

let me know how this goes.

-Cody Joyce
PHP Developer / Technician


0

Response Number 2
Name: smbotans
Date: October 15, 2008 at 18:07:27 Pacific
Reply:

thanks for your reply and time to look into this ... after a couple of days of no replies at this forum, i turned to a friend in poland who fixed it for me ... according to him, the code did not work because of that section:

while ($row_rsInstructors = mysql_fetch_assoc($rsInstructors)){
$sql = mysql_query("SELECT i_email, i_password, i_username
FROM instructors;")
or die ('Select failed because: ' . mysql_error());

thanks again for your help

serge

Keep mentally active.

SEO ANALYSIS Discover what search engines really think of your web site.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: php code caught in a loop

simple php codes www.computing.net/answers/webdevel/simple-php-codes/449.html

PHP: Counting files in a directory. www.computing.net/answers/webdevel/php-counting-files-in-a-directory/2341.html

how to display images in PHP www.computing.net/answers/webdevel/how-to-display-images-in-php-/2164.html