Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML form - PHP not inserting into Database correctly
    text
    copied!<p>i'm only tring to make a form work. Its a similar for than i am fillin now: question, text, tags.</p> <p>Fine,</p> <p><strong>this is when i print the form</strong></p> <pre><code>function imprimir_formulario_pregunta(){ $html = '&lt;form id="pregunta" name ="pregunta" method="post" action="preguntas.php"&gt;'; $html .= '&lt;h2&gt;Pregunta&lt;/h2&gt;'; $html .= '&lt;input name="q" id="q" type="text" value=" "&gt;&lt;/input&gt;'; $html .= '&lt;h2&gt;Explica tu duda&lt;/h2&gt;'; $html .= '&lt;textarea name="texto" id="texto" / &gt;&lt;/textarea&gt;'; $html .= '&lt;h2&gt;Etiquetas (separadas por comas)&lt;/h2&gt;'; $html .= '&lt;input name="tags" id="tags"/&gt;'; $html .= '&lt;input name="responde_a" style="display:none;" id="responde_a" value="0"/&gt;'; $html .= '&lt;button name="pregunta" id="pregunta" type="submit" &gt;Publicar&lt;/button&gt;'; $html .= '&lt;/form&gt;'; echo $html; } </code></pre> <p><strong>this is when i recive data</strong></p> <pre><code>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); </code></pre> <p><strong>this is when i process data</strong></p> <pre><code>function obtener_id_pregunta($p,$t){ $consulta = mysql_query("SELECT * FROM preguntas WHERE pregunta='$p' &amp;&amp; texto='$t'"); while($item = mysql_fetch_array($consulta)){ return $item['id']; } } function post_pregunta($a,$t,$et,$r){ mostrar_notificacion("hemos entrado"); //// ****** if($a != '' &amp;&amp; $t != ''){ $b = $a; guardar_pregunta($b,$t,$r); $id = obtener_id_pregunta($b,$t); $temp = new etiqueta(0, ''); $basura = $temp-&gt;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; } </code></pre> <p>Result:</p> <p>I get the insert in the database done, but the 'q' field has a '' value....</p> <p>Notes: It looses the value in the step <em>*</em>* because it enters in the condition, but it doesn't in the next one wich is the same question...</p> <p>Please tell me you have my answer, been too long on this.. and i need it done this week for class</p> <p>Thanks in advance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload