<?php
//include 'uploads/stuff/connect.php';

    $host = "localhost";
    $username = "oifro";
    $password = "$^id10t!";
    $dbname = "oifro_rktek_mailers";

$link = mysql_connect($host, $username, $password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('oifro_rktek_mailers')
or die('Could not select a database.');
//echo 'Connected successfully';

if(!empty($params['name']))
{
  $name = $params['name'];
}

if(!empty($params['address']))
{
  $address = $params['address'];
}

if(!empty($params['city']))
{
  $city = $params['city'];
}


if(!empty($params['state']))
{
  $state = $params['state'];
}

if(!empty($params['zip']))
{
  $zip = $params['zip'];
}

if(!empty($params['phone']))
{
  $phone = $params['phone'];
}

if(!empty($params['email']))
{
  $email = $params['email'];
}

if(!empty($params['comments']))
{
  
  $comments = $params['comments'];
  $comments = addslashes($comments);
}
  
  $query = "insert into mailers(name,address,city,state,zip,phone,email,comments) values('$name','$address','$city','$state','$zip','$phone','$email','$comments')";
    $mydb = mysql_query($query) or die("Query Failed!");

//    $host = "localhost";
//    $username = "oifro";
//    $password = "$^id10t!";
//    $dbname = "oifro_rktek_mailers";

    // open connection to mysql database
    $connection = @mysqli_connect($host, $username, $password, $dbname) or die("Connection Error " . mysqli_error($connection));

    // fetch mysql table rows
    $sql = "select * from mailers";
    $result = @mysqli_query($connection, $sql) or die("Selection Error " . mysqli_error($connection));

    $fp = fopen('uploads/images/mailers.csv', 'w');

    while($row = mysqli_fetch_assoc($result))
    {
        fputcsv($fp, $row);
    }

    fclose($fp);

    //close the db connection
    mysqli_close($connection);
   




?>