Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/124670-solved-getting-error-for-bulk/
Share on other sites

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>

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

 

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");

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.