从选项值中选择并在数据库中发布

时间:2014-03-27 01:08:51

标签: php mysql

我想通过选择类别并发送文件send.php获取类别的ID并插入产品>类别数据库

这是来自期权价值的mi代码

<?php  
 include("../includes/conexion.inc");

 $conexion = mysql_connect($server,$user,$pw) or die("Error al conectar con el servidor");
 mysql_select_db($db,$conexion);


 function categorias(){
    $sentencia = ("SELECT * FROM categorias ORDER BY nombre");
    $query = mysql_query($sentencia);

    while ($arreglo = mysql_fetch_array($query)) {
        echo '<option value="'.$arreglo[ID].'">'.$arreglo[NOMBRE].'</option>';
    }

 }


?>

这是我的send.php代码

<?php 
    include("conexion.inc");

    $formatos = array('.jpg', '.png');
    $categoria = $_POST[categoria];

    if(isset($_FILES['imagen']) && !empty ($_FILES['imagen']) &&
    isset($_POST['nombre']) && !empty($_POST['nombre']) &&
    isset($_POST['descripcion']) && !empty($_POST['descripcion']) &&
    isset($_POST['direccion']) && !empty($_POST['direccion']) &&
    isset($_POST['telefono']) && !empty($_POST['telefono']))
    {

        $filename = $_FILES['imagen']['name'];
        $tmpfilename = $_FILES['imagen']['tmp_name'];
        $ext = substr($filename, strrpos($filename, '.'));
        $file = "http://localhost/revista_completa/ad/anunciosimg/$filename";
        while (file_exists($file)) {
            mt_srand(time());
            $numero = mt_rand(0,1000);
            $aux = explode(".", $filename);
            $size = sizeof($aux);
            $extention = $aux[$size-1];
            $pos = 0;
            $filename = "";
            while ($pos<$size-1) {
                $filename.= $aux[$pos];
                $pos = $pos+1;
            }
            $filename = $filename.$numero.".".$extention;
            $file = "http://localhost/revista_completa/ad/anunciosimg/$filename";
        }
        if (in_array($ext, $formatos)) {
            if (move_uploaded_file($tmpfilename, "../anunciosimg/$filename")) {
            }else
            {
                echo "ocurrio un error";
            }

        $conexion = mysql_connect($server,$user,$pw)or die("problema al conectar el host");
        mysql_select_db($db, $conexion) or die("problema al conectar ala base de datos");

        mysql_query("INSERT INTO anuncio (IMAGEN,NOMBRE,DESCRIPCION,DIRECCION,TELEFONO,CATEGORIAS)
            (SELECT * FROM categorias)
        VALUES  ('$file','$_POST[nombre]','$_POST[descripcion]','$_POST[direccion]','$_POST[telefono]','$categoria')", $conexion);
        echo "datos insertados correctamente";

        }else
    {
        echo "error al subir archivos";
    }
    }
?>

0 个答案:

没有答案
相关问题