-1

我不知道是否可以,我需要知道如何将电子邮件保存到另一个数据库中,只有当电子邮件输入的表单中有数据(电子邮件)时......让我更好地解释一下。

我有一个用于在我的站点中保存用户的表单,该表单有:

姓名 姓氏 地址 生日 电子邮件 其他人...

我有另一个用于时事通讯的数据库,它是分开的,我只需要保存电子邮件来发送优惠..所以我需要在我的时事通讯数据库中保存电子邮件,只有当用户不插入电子邮件时,电子邮件时事通讯才在表单中存在什么都保存不了……

这是我的表格:

<?php
    include 'include/configs.php';
    $action = isset( $_POST['action'] ) ? $_POST['action'] : "";
    if($action == "create")
    {
        try{
            $stmt = $conn->prepare('INSERT INTO USERS (nombre,apellido,de_casada,estado_civil,genero,referido,f_nacimiento,direccion,departamento,ciudad,IDPAIS,telefono,celular,email) 
            VALUES (:nombre,:apellido,:de_casada,:estado_civil,:genero,:referido,:f_nacimiento,:direccion,:departamento,:ciudad,:IDPAIS,:telefono,:celular,:email)');
                            $stmt->bindParam(':nombre', $_POST['nombre']);
                            $stmt->bindParam(':apellido', $_POST['apellido']);
                            $stmt->bindParam(':de_casada', $_POST['de_casada']);
                            $stmt->bindParam(':estado_civil', $_POST['estado_civil']);
                            $stmt->bindParam(':genero', $_POST['genero']);
                            $stmt->bindParam(':referido', $_POST['referido']);
                            $stmt->bindParam(':f_nacimiento', $_POST['f_nacimiento']);
                            $stmt->bindParam(':direccion', $_POST['direccion']);
                            $stmt->bindParam(':departamento', $_POST['departamento']);
                            $stmt->bindParam(':ciudad', $_POST['ciudad']);
                            $stmt->bindParam(':IDPAIS', $_POST['IDPAIS']);
                            $stmt->bindParam(':telefono', $_POST['telefono']);
                            $stmt->bindParam(':celular', $_POST['celular']);
                            $stmt->bindParam(':email', $_POST['email']);
                            $stmt->execute();

    echo 'Registro ingresado correctamente.';                               
            }
            catch (PDOException $e) 
            {
                error_log($e->getMessage());
                die($e->getMessage());
            }

$stmt = $conn->prepare('INSERT INTO NEWS (email) 
VALUES (:email)');
$stmt->bindParam(
        $stmt->bindParam(':email', $_POST['email']);
        $stmt->execute();

            $dbh = null;   
            echo "<script>";
            echo "window.location.href= 'index.php'";
            echo "</script>";                                   
    }                                   
?>
<form class='form-horizontal' method='post' action='' enctype='multipart/form-data'>
    <fieldset>
        <legend><i class='icon32 icon-square-plus'></i> <?php $translate->__('Add new User to Database'); ?></legend>
        <div class='control-group'>
            <label class='control-label' for='typeahead'><?php $translate->__("User's name"); ?></label>
            <div class='controls'>
                <input type='text' class='span6 typeahead' name='nombre' placeholder='' value='' required/>
            </div>
        </div>
        <div class='control-group'>
            <label class="control-label" for='typeahead'><?php $translate->__('Last Name'); ?></label>
            <div class='controls'>
                <input type='text' class='span6 typeahead' name='apellido' placeholder='' value='' required/>
            </div>
        </div>
        <div class='control-group'>
            <label class='control-label' for='typeahead'><?php $translate->__('Married Name'); ?></label>
            <div class='controls'>
                <input type='text' class='span6 typeahead' name='de_casada' placeholder='' value='' />
            </div>
        </div>
        <div class='control-group'>
            <label class='control-label' for='typeahead'><?php $translate->__('Marital Status'); ?></label>
            <div class='controls'>
                <select id='' name='estado_civil' required>
                    <option value=''><?php $translate->__('Select'); ?></option>
                    <option value='<?php $translate->__('Single'); ?>'><?php $translate->__('Single'); ?></option>
                    <option value='<?php $translate->__('Married'); ?>'><?php $translate->__('Married'); ?></option>
                    <option value='<?php $translate->__('Divorced'); ?>'><?php $translate->__('Divorced'); ?></option>
                    <option value='<?php $translate->__('Widower'); ?>'><?php $translate->__('Widower'); ?></option>
                    <option value='<?php $translate->__('Living Together'); ?>'><?php $translate->__('Living Together'); ?></option>
                </select>
            </div>
        </div>
        <div class='control-group'>
            <label class='control-label' for='typeahead'><?php $translate->__('Gender'); ?></label>
            <div class='controls'>
                <select id='' name='genero' required>
                    <option value=''><?php $translate->__('Select'); ?></option>
                    <option value='<?php $translate->__('Male'); ?>'><?php $translate->__('Male'); ?></option>
                    <option value='<?php $translate->__('Female'); ?>'><?php $translate->__('Female'); ?></option>
                </select>
            </div>
        </div>
        <div class='control-group'>
            <label class='control-label' for='typeahead'><?php $translate->__('Referred by'); ?></label>
            <div class='controls'>
                <input type='text' class='span6 typeahead' name='referido'  placeholder='' />      
            </div>
        </div>
        <div class='control-group'>
            <label class='control-label' for='date01'><?php $translate->__('Date of Birth'); ?></label>
            <div class='controls'>
                <input type='date' class='span6' name='f_nacimiento' placeholder='YYYY-MM-DD' />
            </div>
        </div>
        <div class='control-group'>
            <label class='control-label' for='typeahead'><?php $translate->__('Address'); ?></label>
            <div class='controls'>
                <textarea class='span6 autogrow' name='direccion'></textarea>
            </div>
        </div>
        <div class='control-group'>
            <label class='control-label' for='typeahead'><?php $translate->__('Country'); ?></label>
            <div class="controls">
                <select name="IDPAIS" id="select1" required>    
                    <?php
                        $sql = $conn->prepare("SELECT * FROM lista_paises");
                        $sql->execute();
                        while($row = $sql->fetch(PDO::FETCH_ASSOC)) {
                        echo 
                        '<option value='".$row['id']."'>".$row['opcion']."</option>';
                        }
                    ?> 
                </select>
            </div>
        </div>
        <div class='control-group'>
            <label class='control-label' for='typeahead'><?php $translate->__('State'); ?></label>
            <div class="controls">
                <select name="departamento" id="select2" required></select>
            </div>
        </div>
        <div class='control-group'>
             <label class='control-label' for='typeahead'><?php $translate->__('City'); ?></label>
            <div class='controls'>
                <select name="ciudad" id="select3" required></select>
            </div>
        </div>
        <div class='control-group'>
            <label class='control-label' for='typeahead'><?php $translate->__('Telephone'); ?></label>
            <div class='controls'>
                <input type='text' class='span6 typeahead' name='telefono' placeholder='' value='' />
            </div>
        </div>
        <div class='control-group'>
            <label class='control-label' for='typeahead'><?php $translate->__('Cellphone'); ?></label>
            <div class='controls'>
                <input type='text' class='span6 typeahead' name='celular' placeholder='' value='' />
            </div>
        </div>
        <div class='control-group'>
            <label class='control-label' for='typeahead'><?php $translate->__('E-mail'); ?></label>
            <div class='controls'>
                <input type='email' class='span6 typeahead' name='email' placeholder='' value='' />
            </div>
        </div>
        <div class='form-actions'>
            <input type='hidden' name='action' value='create'  />
            <input type='submit' class='btn btn-primary' value='<?php $translate->__('Save User'); ?>' />
            <input type='reset' class='btn' value='<?php $translate->__('Reset Form'); ?>' />
        </div>
    </fieldset>
</form>

我想我需要在电子邮件的部分隐藏输入或该部分的复选框(保存到另一个数据库)......但我不知道该怎么做......

对不起我的英语不好......不是我的母语

4

1 回答 1

-1

你为什么不在做第二次更新之前问一下?我不知道你为什么需要一个复选框。而且你不必为你糟糕的英语道歉,只是你糟糕的代码哈哈......

if($_POST['email']!="" && ValidateEmail($_POST['email'])) {
$stmt = $conn->prepare('INSERT INTO NEWS (email) 

other insert code here... 


}
于 2013-09-12T18:53:21.800 回答