How to send data to the database, compare and display the site?

1

I'm doing a site where I will add the section "My ideal skateboard", where the user will enter their name, email, age, height, style and experience (beginner, intermediate or professional). best skate style according to the profile.

My question is, how do I send these files to the database, compare them and display the result?

Ex: "Your ideal skateboard is the: traditional"     "Your ideal skateboard is: Longboard"

and so on ..

There is the possibility of doing N's if , but this is not good practice and for maintenance and a possible expansion of the code will be even more complicated.

function calcula(){

	var nome = document.getElementById('nome').value;
        var email = document.getElementById('email').value;
	var altura = document.getElementById('altura').value;
	var peso = document.getElementById('peso').value;

	var sel_estilo = document.getElementById('estilo');
	var valor_estilo = sel_estilo.options[sel_estilo.selectedIndex].value;

	var sel_nivel = document.getElementById('nivel');
	var valor_nivel = sel_nivel.options[sel_nivel.selectedIndex].value;
		
	var calc = altura * peso;

	    if((valor_estilo == 2) && (calc>100) && (valor_nivel == 1)){
	     	alert('Longboard Cruising');
	     }
	}
html, body{
 margin: 0;
 padding: 0;
}

#principal{
 width:25%;
 height:110px;
 margin: 0 auto;
}

input, select{
 border:none;
 width: 100%;
 height: 50px;
 border-sizing: border-box;
 box-shadow: 7px 4px 14px 1px rgba(30, 30, 30, 0.4);
}
<div id="principal">
 <center>
	<input type="text" id="nome" placeholder="Digite seu nome"><br>
	<input type="email" id="email" placeholder="Digite seu email"><br>
	<input type="text" id="idade" placeholder="Digite sua idade"><br>
	<input type="number" id="altura" placeholder="Digite sua altura"><br>
	<input type="number" id="peso" placeholder="Digite seu peso"><br>
	<select id="estilo">
		<option value="selecione"></option>
		<option value="1" id="mano">Manobras radicais</option>
		<option value="2" id="velo">Passeios tranquilos em baixa velocidade</option>
	</select>
	<select id="nivel">
		<option value="selecione"></option>
		<option value="1" id="ini">Iniciante</option>
		<option value="2" id="int">Intermediário</option>
		<option value="3" id="pro">Profissional</option>
	</select> <br>
	<input type="submit" id="enviar" value="Enviar" onclick="calcula()">
	</center>
	</div>

This is an outline I made if I did with 541618 if's rsrs

How can I post this data to the database, "do if's " and return the value to the user / site?

  

OBS 1: Obviously, I do not want the code ready, but at least one way to go ..   NOTE 2: The calculation used is just one example. The logic I will use is more elaborate.   NOTE 3: I am open to solutions in JQuery as well.

    
asked by anonymous 06.04.2016 / 21:21

1 answer

1

If you do not intend to use a backend framework (which I recommend using), you could make the connection as in this example .

var connection = new ActiveXObject("ADODB.Connection") ;

var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";

connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");

rs.Open("SELECT * FROM table where ideade = " + idade + " and altura like " + altura, connection);
rs.MoveFirst
if(!rs.eof)
{
   document.write("Seu skate ideal é o " + rs.fields("skate"));
   rs.movenext;
}

rs.close;
connection.close;
    
06.04.2016 / 22:09