1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP and MSQL database

Discussion in 'PHP' started by neil_12s, Jul 26, 2010.

?

How to connect MySQL with PHP?

  1. email address collectingl

    0 vote(s)
    0.0%
  2. Mailing list

    100.0%
Multiple votes are allowed.
  1. #1
    I will be grateful if someone could help me with a PHP program to connect MYSQL database to a webpage to collect email addresses.

    Thanks

    Wilfred
     
    Last edited: Jul 26, 2010
    neil_12s, Jul 26, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    Run the following SQL command to create 'email' table:
    
    CREATE TABLE emails ( email CHAR(50) );
    
    Code (markup):
    
    <?php
    $link = @mysqli_connect("localhost","username","password");
    @mysqli_set_charset($link, "utf8");
    @mysqli_select_db($link, "emails");
    
    echo "<form action='.'  method='post'>";
    echo "Email: <input type='text' name='email' /></form>";
    if (isset($_POST['email'])) {
       $email = $_POST['email'];
       @mysqli_query($link, "INSERT INTO emails VALUES ($email)") or die("Failed.");
       echo "Success";
    }
    
    ?>
    
    PHP:
    The basics should be something like that. How would you like it?
     
    Rainulf, Jul 26, 2010 IP
    ElitePrime likes this.
  3. ElitePrime

    ElitePrime Active Member

    Messages:
    682
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    70
    #3
    Thanks +Rep :D
    Also how do you access the database of email? Sorry not very good at SQL databases.
     
    ElitePrime, Jul 26, 2010 IP
  4. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #4
    you can access the database and get all records like so:

    
    <?php
    // Connect to the database.
    mysql_connect($url, $username, $password);
    mysql_select_db($db_name) or die(mysql_error());
    
    // Get the emails from the database table "emails".
    $query = mysql_query("SELECT * FROM emails") or die(mysql_error());
    
    // Go through each email retrieved from the database and output them on the page.
    while($row = mysql_fetch_array($query)) {
          echo $row['email'];
    }
    ?>
    
    PHP:

    You can do other things with the data besides just output it too if you like.
     
    Thorlax402, Jul 27, 2010 IP
  5. sandy_joy

    sandy_joy Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi, Here We introduce that code, that's help you,Just see them

    <?php
    if(isset($_POST['posted']))
    {
    $email_id=$_POST['dir_email_id'];
    $connect=mysql_connect('localhost','root','');
    $db=mysql_select_db('dir_db',$connect);
    // Now, We Perform Saving Operation.
    if(isset($_POST['dir_save']) == 'Save')
    {
    $query=mysql_query("INSERT INTO dir_table(emailid)VALUES('$email_id')",$connect);
    }
    //Retrive Emial Id Which i Save In Databse

    $query=mysql_query('SELECT * FROM dir_table',$connect);
    while($row=mysql_fetch_array($query))
    {
    $my_email_id=$row['emailid'];
    echo $my_email_id;
    exit();
    }
    }

    ?>

    <form name="index_dir" method="post" action="index_dir.php">
    <table align="center" border="">
    <tr>
    <td>
    <b style="background-color:#063">Email Id</b>
    <input type="text" name="dir_email_id" value="Email Id" style="background-color:#966">
    </td>
    </tr>
    <tr>
    <td><input type="hidden" name="posted" value="true>"></td>
    <td>
    <input type="submit" name="dir_submit" value="GO" style="background-color:#063">
    </td>
    <td>
    <input type="submit" name="dir_save" value="Save" style="background-color:#063">
    </td>
    </tr>
    </table>
    </form>
     
    Last edited: Jul 27, 2010
    sandy_joy, Jul 27, 2010 IP