HTML formu - PHP doğru Veritabanı içine sokarak değil

0 Cevap php

i'm only tring to make a form work. Its a similar for than i am fillin now: question, text, tags.

Güzel

this is when i print the form

function imprimir_formulario_pregunta(){ 
    $html = '<form id="pregunta" name ="pregunta" method="post" action="preguntas.php">';
    $html .= '<h2>Pregunta</h2>';

    $html .= '<input name="q" id="q" type="text" value=" "></input>';
    $html .= '<h2>Explica tu duda</h2>';
    $html .= '<textarea name="texto" id="texto" /
                    ></textarea>';
    $html .= '<h2>Etiquetas (separadas por comas)</h2>';
    $html .= '<input name="tags" id="tags"/>';
    $html .= '<input name="responde_a" style="display:none;" id="responde_a" value="0"/>';


    $html .= '<button name="pregunta" id="pregunta" type="submit" >Publicar</button>';

    $html .= '</form>';

    echo $html;

}

this is when i recive data

if(isset($_POST['pregunta'])){
    $p_title = $_POST['q'];
    $p_text = $_POST['texto'];
    $p_et = $_POST['etiquetas'];
    $p_resp = $_POST['responde_a'];
    post_pregunta($p_title,$p_text, $p_et, $p_resp);

this is when i process data

function obtener_id_pregunta($p,$t){
    $consulta = mysql_query("SELECT * FROM preguntas WHERE pregunta='$p' && texto='$t'");
    while($item = mysql_fetch_array($consulta)){
        return $item['id'];
    }
}

function    post_pregunta($a,$t,$et,$r){
    mostrar_notificacion("hemos entrado");
    //// ******
    if($a != '' && $t != ''){
        $b = $a;
        guardar_pregunta($b,$t,$r);
        $id = obtener_id_pregunta($b,$t);
        $temp = new etiqueta(0, '');
        $basura = $temp->guardar_etiquetas($et, $id, $_SESSION['id']);



    }else
        mostrar_notificacion("hemos salido $a $t");
}

function guardar_pregunta($p,$t,$r){
    $id_tmp = $_SESSION['id'];
    $insert = "INSERT INTO preguntas (pregunta,texto,id_usuario,fecha,responde_a) VALUES ('$p','$t','$id_tmp',NOW(),'$r')";
    $qry = mysql_query($insert);
    if(mysql_affected_rows())
    {
        mostrar_notificacion("La pregunta $p ($t)($r) se guardo");
        return true;
    }
    else
    {
        mostrar_notificacion("Error Ingresando datos");
        return false;
    }
    return false;
}

Sonuç:

Yaptığım veritabanında ekleme olsun, ama 'q' alanı bir'' değeri vardır ....

Notes: It looses the value in the step ** because it enters in the condition, but it doesn't in the next one wich is the same question...

.. Bu çok uzun zaman oldu, benim cevabım var Lütfen bana ve ben o sınıf için bu hafta yapılması gerekir

Şimdiden teşekkürler

0 Cevap