+ Reply to Thread
Results 1 to 5 of 5

Thread: Php database

  1. #1
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Question Php database

    Below is a script I'm using to retrieve a record from a mySQL database and then use it to send a message to.

    I'm having some trouble however with putting the retrieved table entry into email part of the code.

    PHP Code:
    <?php 
    //Change these
    $db 'my_database';
    $user 'my_user';
    $password 'my_password';

    if(!
    mysql_connect('localhost'$user$password)) {
     exit(
    mysql_error());
    }
    if(!
    mysql_select_db($db)) exit(mysql_error());

    // Get a specific result from the "example" table
    $result mysql_query("SELECT * FROM `my_table`") or die(mysql_error());  

    // Loop to get multiple results
    while($row mysql_fetch_array($result)){
    echo 
    "Name: ".$row['name'];
    echo 
    "Email: ".$row['email'];
    }

    ?>

    <?php
    $from 
    "my_email";
    $subject "my_subject";
    //Begin HTML Email Message
    $message "my_message";
     
    echo 
    '  ';
    //end of message
    $headers  "From: $from\r\n";
    $headers "Content-type: text/html\r\n";
    $to "$row['email']";
     
    mail($to$subject$message$headers); 
     
    exit();
    ?>
    Does anyone have any knowledge on what I'm doing wrong it would be great to hear from you } thanks

  2. #2
    sunils's Avatar
    sunils is offline x10 Spammer sunils is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Chennai ,India
    Posts
    2,264

    Re: Php database

    I think you wanted to send the database data to all the emails reterived. here is what i modified.
    PHP Code:
    <?php  
     
    //Change these 
     
    $db 'my_database'
     
    $user 'my_user'
     
    $password 'my_password'
     if(!
    mysql_connect('localhost'$user$password)) { 
       exit(
    mysql_error()); 
     } 
     
     if(!
    mysql_select_db($db)) exit(mysql_error()); 
     
    // Get a specific result from the "example" table 
     
     
    $result mysql_query("SELECT * FROM `my_table`") or die(mysql_error());   
     
    // Loop to get multiple results 
     
     
    $from "my_email"
     
    $subject "my_subject"
     while(
    $row mysql_fetch_array($result)){ 
      
    $message $row['name']; 
      
    $headers "MIME-Version: 1.0\r\n";
      
    $headers.= "Content-Type: text/html;";
      
    $headers.= "Charset=iso-8859-1\r\n";
      
    $headers.= "From: ".$from
      
    $headers "Content-type: text/html\r\n"
      
    $to $row['email']; 
      
    mail($to$subject$message$headers);  
     } 
     exit(); 
    ?>
    this code will send the name reterived from the database to the email address reterived from the database.

    if this is not similar to your requirement. Post your exact requirement like what data from database you need to send and to which email id. Whether to a single email id or to email ids that will be reterived from the database.
    Last edited by sunils; 11-20-2008 at 08:47 AM.
    [LEFT][B]Sunil Sankar
    -------------------------------------------------------------------------

  3. #3
    balaji2u's Avatar
    balaji2u is offline x10 Lieutenant balaji2u is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Senthamil Nadu,India
    Posts
    410

    Re: Php database

    Sunil is correct .but the headers variables are with out the . {DOT} which will cause it to not append the previous stored strings?
    or is it will not create problems .i think sunil leave this because may be php automatically appends the string if im right!!!
    Submit your Site Links Now ! >>> :cool:
    Live Aritlces Free Articles and Links Directory


  4. #4
    sunils's Avatar
    sunils is offline x10 Spammer sunils is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Chennai ,India
    Posts
    2,264

    Re: Php database

    Thanks balaji for bringing to the my notice... you should concatenate it otherwise the previous values will be over written
    [LEFT][B]Sunil Sankar
    -------------------------------------------------------------------------

  5. #5
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Re: Php database

    stirling work for sure - worked like a dream. Thanks_

+ Reply to Thread

Similar Threads

  1. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  2. php & database help
    By playdnd in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 12-05-2007, 10:55 PM
  3. Cambios IMPORTANTES en PHP.
    By Fedlerner in forum Noticias y Anuncios
    Replies: 1
    Last Post: 11-06-2007, 11:13 AM
  4. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM
  5. search database with php
    By niahossain in forum Scripts & 3rd Party Apps
    Replies: 4
    Last Post: 10-17-2007, 11:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers