addin newsletter subscribers to db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
g0nline
Forum Newbie
Posts: 6
Joined: Sat Sep 25, 2010 4:33 pm

addin newsletter subscribers to db

Post by g0nline »

i wanted to make a script to add my emails to the db. here is the one i used
everytime i submit it i get this error
Access denied for user 'apache'@'localhost' (using password: NO)
i realy dont get this as i havnt mentioned apache once and my password is password...
this was uploaded to server after testing it on xampp
<?php

Code: Select all

if (isset ($_POST['email'])){
   
     $email = $_POST['email'];

     $email = stripslashes($email); 
    
     $email = strip_tags($email);

 DB INFO HERE

     $emailCHecker = mysql_real_escape_string($email);
    $emailCHecker = eregi_replace("`", "", $emailCHecker);
     // Database duplicate e-mail check setup for use below in the error handling if else conditionals
     $sql_email_check = mysql_query("SELECT email FROM newsletter WHERE email='$emailCHecker'");
     $email_check = mysql_num_rows($sql_email_check); 

     // Error handling for missing data
     if ((!$email)) { 

     $errorMsg = 'ERROR: You did not submit the following required information:<br /><br />';
  
    if(!$email){ 
       $errorMsg .= ' * Email Address<br />';      
     }
    if(!$email2){ 
       $errorMsg .= ' * Confirm Email Address<br />';        
     }       
      
     } else { // Error handling is ended, process the data and add member to database
     ///////////////////
     $email = mysql_real_escape_string($email);
    
   
    $email = eregi_replace("`", "", $email);
    
       $sql = mysql_query("INSERT INTO newsletter (email, sign_up_date) 
     VALUES('$email', now())")  
     or die (mysql_error());
 
     $id = mysql_insert_id();

      $to = "$email";
                               
    $subject = "Welcome to our newsletter ";
    //Begin HTML Email Message
    $message = "Hello,

 Thank you for signing up to our newsletter. 
 If you would ever like to leave please email us. Also, if you would like info about having your websites info in our newsletter, please email us. 
   newsletteradmin@g0nline.com";
   //end of message
   $headers  = "From: $from\r\n";
    $headers .= "Content-type: text\r\n";

    mail($to, $subject, $message, $headers);
   ;


   

   } // Close else after duplication checks

} else { // if the form is not posted with variables, place default empty variables so no warnings or errors show
     
     $errorMsg = "";
     $email = "";
}

?>



<style type="text/css">
.brightRed {color: #F00;
}
.center {   text-align: center;
}
</style>
<table width="100" border="1" align="center">
  <tr>
    <td><table width="275" align="center" cellpadding="5"><form id="form1" name="form1" method="post" action="mailing1.php">
      <tr>
        <td width="257" height="29" align="center">Please enter your email bellow to recieve our montly newsletter!<br>
         </td>
      </tr>
      <tr>
        <td height="29"><span class="center">
          <input name="email" type="text" class="formFields" id="email" value="<?php print "$email"; ?>" size="25" maxlength="100" />
          <input type="submit" name="button" id="button" value="Submit" />
        </span></td>
      </tr>
    </table></td>
  </tr>
</table>
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: addin newsletter subscribers to db

Post by McInfo »

The relevant part of the script has been obscured with "DB INFO HERE".

The arguments for mysql_connect() are probably incorrect.

Causes of Access-Denied Errors
g0nline
Forum Newbie
Posts: 6
Joined: Sat Sep 25, 2010 4:33 pm

Re: addin newsletter subscribers to db

Post by g0nline »

McInfo wrote:The relevant part of the script has been obscured with "DB INFO HERE".

The arguments for mysql_connect() are probably incorrect.

Causes of Access-Denied Errors
what i mean is that sayi use these...

Code: Select all

$db_host = "localhost";
// Place the username for the MySQL database here
$db_username = "admin"; 
// Place the password for the MySQL database here
$db_pass = "password"; 
// Place the name for the MySQL database here
$db_name = "gnline_users";
id still get the same error....

i know my info is correct....
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: addin newsletter subscribers to db

Post by McInfo »

g0nline wrote:Access denied for user 'apache'@'localhost' (using password: NO)
[...]
this was uploaded to server after testing it on xampp
Do you administer the server yourself, or do you rent the server? If you rent the server, there is a good chance the host name is not "localhost" but an IP address instead. There is also a very good chance the user name is not "apache" and that a password is required.
g0nline
Forum Newbie
Posts: 6
Joined: Sat Sep 25, 2010 4:33 pm

Re: addin newsletter subscribers to db

Post by g0nline »

well i dont host it myself, unlimited webhosting.co.uk host it but they have checked it out and all the info is correct.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: addin newsletter subscribers to db

Post by McInfo »

Does your host have phpMyAdmin?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: addin newsletter subscribers to db

Post by John Cartwright »

From the error message, it looks like you aren't passing the correct information at all.

Apache is the default username, if none was specified. Your error also shows you aren't specifying a password. Therefore, I would double check you are using the correct variable names.

Also, please use the appropriate tags when posting code.
g0nline
Forum Newbie
Posts: 6
Joined: Sat Sep 25, 2010 4:33 pm

Re: addin newsletter subscribers to db

Post by g0nline »

McInfo wrote:Does your host have phpMyAdmin?
yh, it does...
g0nline
Forum Newbie
Posts: 6
Joined: Sat Sep 25, 2010 4:33 pm

Re: addin newsletter subscribers to db

Post by g0nline »

John Cartwright wrote:From the error message, it looks like you aren't passing the correct information at all.

Apache is the default username, if none was specified. Your error also shows you aren't specifying a password. Therefore, I would double check you are using the correct variable names.

Also, please use the appropriate tags when posting code.

well the info i was using was

$db_host = "localhost";
// Place the username for the MySQL database here
$db_username = "admin";
// Place the password for the MySQL database here
$db_pass = "password";
// Place the name for the MySQL database here
$db_name = "users";
i know all this info is correct and it was even looked over by my provider who said that all the db info waas correct.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: addin newsletter subscribers to db

Post by McInfo »

Are you able to log in to phpMyAdmin with those credentials?
g0nline
Forum Newbie
Posts: 6
Joined: Sat Sep 25, 2010 4:33 pm

Re: addin newsletter subscribers to db

Post by g0nline »

McInfo wrote:Are you able to log in to phpMyAdmin with those credentials?
yh, thats why i dont get it:S
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: addin newsletter subscribers to db

Post by John Cartwright »

g0nline wrote:
John Cartwright wrote:From the error message, it looks like you aren't passing the correct information at all.

Apache is the default username, if none was specified. Your error also shows you aren't specifying a password. Therefore, I would double check you are using the correct variable names.

Also, please use the appropriate tags when posting code.

well the info i was using was

$db_host = "localhost";
// Place the username for the MySQL database here
$db_username = "admin";
// Place the password for the MySQL database here
$db_pass = "password";
// Place the name for the MySQL database here
$db_name = "users";
i know all this info is correct and it was even looked over by my provider who said that all the db info waas correct.
It would be helpful to see the the code which actually connects to the database to verify you are using the correct variables. If those are in fact the variables being passed to mysql_connect() then you wouldn't see the error you are getting.
Post Reply