How to send data to the database, compare and display on the website?

Asked

Viewed 87 times

1

I am making a site where I will add the section "My ideal skateboard", where the user will enter his name, email, age, height, style and experience (beginner, intermediate or professional), doing this will indicate what the best style of skateboard 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 possible code expansion will become 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 a sketch I made if I did it with 541618 if's rsrs

How can I roll these dice to the database, "make the if's" and return the value to the user/site?

OBS 1: Obviously, I don’t want the code ready, but at least one way to go.. OBS 2: The calculation used is just one example. The logic I will use is more elaborate.
OBS 3: I’m open to Jquery solutions as well.

1 answer

1

If you have no intention of using a framework to back-end (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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.