sandbudd Posted September 17, 2008 Share Posted September 17, 2008 Hi guys I have a script for bulk email pulling email address from mysql database. I keep getting No database selected I have checked and double checked my database name, pass, etc... any ideas? <?php ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); $hostname = ""; $database = ""; $username = ""; $password = ""; $petitionscript = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); ?> <? if (isset($_POST['submit'])) { $subject = $_POST['subject']; $message = $_POST['message']; $query="SELECT mail FROM signature"; $result = mysql_query($query) or die (mysql_error()); $num = mysql_num_rows($result); $i=0; while ($i < $num) { $email=mysql_result($result,$i,"email"); mail($email, $subject, $message, "From:>\nX-Mailer: PHP/" . phpversion()); echo "Email sent to: " . $email . "<br />"; $i++; } } ?> <br /> <form name="email" action="<?=$_SERVER['email.php']?>" method="post"> Subject <br /> <input name="subject" type="text" size="50" id="subject"><br /><br /> Message <br /> <textarea name="message" cols="50" rows="10" id="message"></textarea> <br /><br /> <input type="submit" name="submit" value="Email!"> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/124670-solved-getting-error-for-bulk/ Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 Try adding the connection variable to the query function. $result = mysql_query($query,$petitionscript) or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/124670-solved-getting-error-for-bulk/#findComment-643940 Share on other sites More sharing options...
wildteen88 Posted September 17, 2008 Share Posted September 17, 2008 You need to call mysql_select_db after mysql_(p)connect Also do not mix and match PHP tags within your script, use one or the other. Quote Link to comment https://forums.phpfreaks.com/topic/124670-solved-getting-error-for-bulk/#findComment-643944 Share on other sites More sharing options...
sandbudd Posted September 17, 2008 Author Share Posted September 17, 2008 F1Fan I get the same error? wildteen88 can you take a little of the code and show me exactly where and what I need to add please Quote Link to comment https://forums.phpfreaks.com/topic/124670-solved-getting-error-for-bulk/#findComment-643946 Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 Sorry, I also forgot this (as wildteen pointed out): mysql_select_db() You need to tell it which database it needs to use, even if there's only one. Like this: <?php ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); $hostname = ""; $database = ""; $username = ""; $password = ""; $petitionscript = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db('dbnamehere',$petitionscript); ?> <? if (isset($_POST['submit'])) { $subject = $_POST['subject']; $message = $_POST['message']; $query="SELECT mail FROM signature"; $result = mysql_query($query,$petitionscript) or die (mysql_error()); $num = mysql_num_rows($result); $i=0; while ($i < $num) { $email=mysql_result($result,$i,"email"); mail($email, $subject, $message, "From:>\nX-Mailer: PHP/" . phpversion()); echo "Email sent to: " . $email . "<br />"; $i++; } } ?> <br /> <form name="email" action="<?=$_SERVER['email.php']?>" method="post"> Subject <br /> <input name="subject" type="text" size="50" id="subject"><br /><br /> Message <br /> <textarea name="message" cols="50" rows="10" id="message"></textarea> <br /><br /> <input type="submit" name="submit" value="Email!"> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/124670-solved-getting-error-for-bulk/#findComment-643950 Share on other sites More sharing options...
sandbudd Posted September 17, 2008 Author Share Posted September 17, 2008 wow now I get this several times on the page? Warning: mail() [function.mail]: SMTP server response: 503 5.5.2 Need Rcpt command. in D:\hshome\sandbudd.com\newsletter.php on line 36 Email sent to: Warning: mysql_result() [function.mysql-result]: email not found in MySQL result index 2 in D:\hshome\sandbudd.com\newsletter.php on line 34 Quote Link to comment https://forums.phpfreaks.com/topic/124670-solved-getting-error-for-bulk/#findComment-643963 Share on other sites More sharing options...
wildteen88 Posted September 17, 2008 Share Posted September 17, 2008 In your query you return the field mail from the signature table. However you're telling mysql_result to retrieve the email field. mysql_result can only return the fields you specify in your query. Prehaps you mean $email=mysql_result($result,$i,"mail"); Quote Link to comment https://forums.phpfreaks.com/topic/124670-solved-getting-error-for-bulk/#findComment-643969 Share on other sites More sharing options...
sandbudd Posted September 17, 2008 Author Share Posted September 17, 2008 changed to mail and the one fell off...this one is still there? Warning: mail() [function.mail]: SMTP server response: 503 5.5.2 Need Rcpt command. in D:\hshome\sandbudd.com\newsletter.php on line 36 Email sent to: Quote Link to comment https://forums.phpfreaks.com/topic/124670-solved-getting-error-for-bulk/#findComment-643973 Share on other sites More sharing options...
sandbudd Posted September 17, 2008 Author Share Posted September 17, 2008 now it shows page can not be displayed and the mail does not get sent... could it be here? <form name="email" action="<?=$_SERVER['email.php']?>" method="post"> Quote Link to comment https://forums.phpfreaks.com/topic/124670-solved-getting-error-for-bulk/#findComment-643995 Share on other sites More sharing options...
sandbudd Posted September 17, 2008 Author Share Posted September 17, 2008 well guys got it working but now I get a time out error..any work arounds? CGI Timeout The specified CGI application exceeded the allowed time for processing. The server has deleted the process. Quote Link to comment https://forums.phpfreaks.com/topic/124670-solved-getting-error-for-bulk/#findComment-644016 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.