site PHP surveys dynamics

0

I am in a dilemma with this project, I am new to PHP and I am finishing a survey project only that I am very stuck in a modification that I want to make at the end of the project.

I have my code where I create the survey.

<section id="form">
    <form action="crearPreguntas.php" class="contact_form" method="post">
        <ul>
            <li>
                <h2>Crear Encuesta</h2>
            </li>   
            <li>
                <label for="user">Encuesta:</label>
                <input type="text" name="titulo" placeholder="Encuesta" required/>
                    
            </li>
            
            <li>
                <label for="preguntas">Preguntas:</label>
                <input type="number" name="preguntas" placeholder="Preguntas" min="0" max="15" required/>
                    
            </li>
            <li>
                <input type="submit" class="submit" value="Crear"/>
            </li>
        </ul>
    </form>
</section> 

and then where I create the questions

<?php 
include 'header.php'; 
//Capturamos los datos que vienen por post 
$titulo = $_POST["titulo"]; 
$preguntas = $_POST["preguntas"]; 


?> 
<section id="form"> 
    <form action="insertarPregunta.php" class="contact_form" method="post"> 
        <h3><?php echo $titulo; ?></h3> 
        <table> 
            <?php 
            //Clico for que recorre la cantidad de prguntas ingresadas 
            for ($i=1; $i <= $preguntas; $i++){ 
            
            ?> 
            <tr> 
                <td>Preguntas <?php echo $i; ?> &nbsp; 
                <input name="p<?php echo $i; ?>" type="text" size="100" maxlength="100"></td> 
                               
            </tr> 
            <?php }?> 
             
        </table><br><input class="submit" type="submit" value="Insertar"> 
          <input name="titulo" type="hidden" value="<?php echo $titulo; ?>"> 
          <input name="preguntas" type="hidden" value="<?php echo $preguntas; ?>"> 
    </form> 
</section> 
<style> 
    #center{ 
        margin: -10px; 
        padding: 0px 0px 20px; 
         
    } 
</style> 
<center id="center"> 
    <a id="pagina1" href="javascript:window.history.back();">&laquo;volver Atras</a> 
</center>

and I keep my survey and my questions.

<?php 
$titulo = $_POST["titulo"]; 
$preguntas = $_POST["preguntas"]; 
         
//conexion con Base de datos 
require 'conexion.php'; 
//obtenemos la fecha del sistema 
$fecha_actual = date("y-m-d"); 

//insertamos la nueva encuesta 

$sql = "INSERT INTO encuestas(titulo, fecha) VALUES ('$titulo' ,'$fecha_actual')"; 
$sql = mysqli_query($conexion,$sql); 

// Ahora obtenemos la id de la encuesta que acabamos de insertat 
$sql = "SELECT id FROM encuestas ORDER BY fecha"; 
$sql = mysqli_query($conexion, $sql); 
while ($row = mysqli_fetch_array($sql)){ 
    $id = $row["id"]; 
} 
//recorremos las preguntas 
for ($i = 1; $i <= $preguntas; $i++){ 
    //Obtenemos el texto de la pregunta 
    $preg = p.$i; 
    $pas = $_POST[$preg]; 
    $texto =  $pas; 
     
    //y lo insertamos 
    $sql = "INSERT INTO respuestas(texto, idenc) VALUES ('$texto' ,'$id')"; 
    $sql = mysqli_query($conexion,$sql); 
} 
header("Location: crearEncuesta.php"); 

?>
Antiguo Hoy, 10:54
antonio_dsanchez

Fecha de Ingreso: abril-2015
Mensajes: 90
Antigüedad: 2 años, 10 meses
Puntos: 0
encuestas PHP
hola a todos 

I am in a dilemma with this project, I am new to PHP and I am finishing a survey project only that I am very stuck in a modification that I want to make at the end of the project.

I have my code where I create the survey.

HTML Code:

<section id="form">
    <form action="crearPreguntas.php" class="contact_form" method="post">
        <ul>
            <li>
                <h2>Crear Encuesta</h2>
            </li>   
            <li>
                <label for="user">Encuesta:</label>
                <input type="text" name="titulo" placeholder="Encuesta" required/>

            </li>

            <li>
                <label for="preguntas">Preguntas:</label>
                <input type="number" name="preguntas" placeholder="Preguntas" min="0" max="15" required/>

            </li>
            <li>
                <input type="submit" class="submit" value="Crear"/>
            </li>
        </ul>
    </form>
</section> 

and then where I create the questions

PHP Code:

<?php 
include 'header.php'; 
//Capturamos los datos que vienen por post 
$titulo = $_POST["titulo"]; 
$preguntas = $_POST["preguntas"]; 


?> 
<section id="form"> 
    <form action="insertarPregunta.php" class="contact_form" method="post"> 
        <h3><?php echo $titulo; ?></h3> 
        <table> 
            <?php 
            //Clico for que recorre la cantidad de prguntas ingresadas 
            for ($i=1; $i <= $preguntas; $i++){ 

            ?> 
            <tr> 
                <td>Preguntas <?php echo $i; ?> &nbsp; 
                <input name="p<?php echo $i; ?>" type="text" size="100" maxlength="100"></td> 

            </tr> 
            <?php }?> 

        </table><br><input class="submit" type="submit" value="Insertar"> 
          <input name="titulo" type="hidden" value="<?php echo $titulo; ?>"> 
          <input name="preguntas" type="hidden" value="<?php echo $preguntas; ?>"> 
    </form> 
</section> 
<style> 
    #center{ 
        margin: -10px; 
        padding: 0px 0px 20px; 

    } 
</style> 
<center id="center"> 
    <a id="pagina1" href="javascript:window.history.back();">&laquo;volver Atras</a> 
</center>

and I keep my survey and my questions.

PHP Code:

<?php 
$titulo = $_POST["titulo"]; 
$preguntas = $_POST["preguntas"]; 

//conexion con Base de datos 
require 'conexion.php'; 
//obtenemos la fecha del sistema 
$fecha_actual = date("y-m-d"); 

//insertamos la nueva encuesta 

$sql = "INSERT INTO encuestas(titulo, fecha) VALUES ('$titulo' ,'$fecha_actual')"; 
$sql = mysqli_query($conexion,$sql); 

// Ahora obtenemos la id de la encuesta que acabamos de insertat 
$sql = "SELECT id FROM encuestas ORDER BY fecha"; 
$sql = mysqli_query($conexion, $sql); 
while ($row = mysqli_fetch_array($sql)){ 
    $id = $row["id"]; 
} 
//recorremos las preguntas 
for ($i = 1; $i <= $preguntas; $i++){ 
    //Obtenemos el texto de la pregunta 
    $preg = p.$i; 
    $pas = $_POST[$preg]; 
    $texto =  $pas; 

    //y lo insertamos 
    $sql = "INSERT INTO respuestas(texto, idenc) VALUES ('$texto' ,'$id')"; 
    $sql = mysqli_query($conexion,$sql); 
} 
header("Location: crearEncuesta.php"); 

?>

and finally I show my questionnaire according to the selection of the user

<?php 

//capturamos la variable que viene por post del archivo ver encuesta  

$opcion = $_POST["opcion"]; 
require 'conexion.php'; 
include 'header.php'; 

//seleccionamos la encuesta de acuerdo a la variable $opcion 
$consulta = "SELECT * FROM encuestas WHERE id=$opcion"; 

//Ahora recorremos los datos Titulo, fecha, id de la encuesta seleccionada 

$consulta = mysqli_query($conexion, $consulta); 
while ($row = mysqli_fetch_array($consulta)){ 
    $titulo = $row["titulo"]; 
    $fecha = $row["fecha"]; 
    $id = $row["id"]; 
} 

?> 
<section id="form"> 
    <form action="inserVotacion.php" class="contact_form" name="form1" method="post"> 
        <table> 
            <tr> 
                <!--Mostramos el titulo de la encuesta--> 
                <td colspan="2"> <h3><?php echo $titulo; ?></h3></td> 
            <input type="hidden" name="id" value="<?php echo $id; ?>"> 
            </tr> 
            <?php 
            //consulta que captura el texto , id de la tabla respuestas 
            $sql = "SELECT texto,id FROM respuestas WHERE idenc='$id'"; 
            $sql = mysqli_query($conexion,$sql); 
            //ahora recorremos los datos texto, id que estan vinculadas a la cuenta seleccionada 
            while ($row = mysqli_fetch_array($sql)){ 
                $texto = $row["texto"]; 
                $idres = $row["id"]; 
                  
            ?> 
             
         
            <tr> 
              <!--  <td width="50"><input type="radio" name="opcion" value="<?php echo $idres; ?>" required</td> 
                <td width="470"><?php echo $texto; ?></td>--> 
                <td width="50"><?php echo $idres; ?></td> 
                <td width="470"><?php echo $texto; ?></td> 
                <td> SI <input type="radio" name="radio<?php echo $idres; ?>" value="SI"></td> 
                <td> NO <input type="radio" name="radio<?php echo $idres; ?>" value="NO"></td> 
                <td><textarea name="comentarios<?php echo $idres; ?>" rows="5" cols="20">Escribe aquí tus Hallazgos</textarea></td> 
                <td><textarea name="acciones<?php echo $idres; ?>" rows="5" cols="20">Escribe aquí tus Acciones Correctivas</textarea></td> 
            </tr> 
            <?php } ?> 
            <tr> 
                <td> 
                    <input class="submit" type="submit" value="Guardar"></input> 
                <td>Esta encuesta esta&aacute; del <?php echo $fecha; ?></td> 
                </td> 
            </tr> 
        </table> 
    </form> 
</section> 
<center> 
    <div id="paginador"> 
        <form action="grafico.php" method="post"> 
            <a id="pagina1" href="javascript:window.history.back();">&laquo; Volver Atras</a> 
            <input type="hidden" name="opcion" value="<?php echo $opcion;?>"> 
            <input class="submit" type="submit" value="Ver"></input> 
        </form> 
    </div> 
</center> 
<?php 
        include 'foother.php'; 
?>

I only have one question at the time of saving my questionnaire.

in the part of

<tr> 
              <!--  <td width="50"><input type="radio" name="opcion" value="<?php echo $idres; ?>" required</td> 
                <td width="470"><?php echo $texto; ?></td>--> 
                <td width="50"><?php echo $idres; ?></td> 
                <td width="470"><?php echo $texto; ?></td> 
                <td> SI <input type="radio" name="radio<?php echo $idres; ?>" value="SI"></td> 
                <td> NO <input type="radio" name="radio<?php echo $idres; ?>" value="NO"></td> 
                <td><textarea name="comentarios<?php echo $idres; ?>" rows="5" cols="20">Escribe aquí tus Hallazgos</textarea></td> 
                <td><textarea name="acciones<?php echo $idres; ?>" rows="5" cols="20">Escribe aquí tus Acciones Correctivas</textarea></td> 
            </tr>

As I can do to save in my database, I know that I have to keep asking question by question and answer in a shekel but I do not know how to do this.

these are my databases

BD_encuestas 
ID
Fecha
titulo

BD_preguntas
id
idenc
testo

BD_respuestas
id
id_pregunta
idenc
valor
accion 
hallazfo
fecha
    
asked by antonio sanchez 13.02.2018 в 21:59
source

0 answers