i'm tring make form work. similar fillin now: question, text, tags.
fine,
this when print 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 when 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 when process data
function obtener_id_pregunta($p,$t){ $consulta = mysql_query("select * preguntas 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 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; }
result:
i insert in database done, 'q' field has '' value....
notes: looses value in step ** because enters in condition, doesn't in next 1 wich same question...
please tell me have answer, been long on this.. , need done week class
thanks in advance
it's hard see what's going on - @vincebowdren says, need debug every step of way.
however, more worryingly you're using $_post data directly in sql query - this sql injection attack waiting happen.
ensure wrap all such variables in mysql_real_escape_string function within queries.
e.g.:
$insert = "insert preguntas (pregunta,texto,id_usuario,fecha,responde_a) values ('".mysql_real_escape_string($p)."','".mysql_real_escape_string($t)."','$id_tmp',now(),'".mysql_real_escape_string($r)."')";
see how can prevent sql injection in php? more information.
Comments
Post a Comment