This question already has an answer here:
i am trying to insert values to table in my db but it does not work also, i am using javascript in my code but it does not work. i am specifying my user by role number so, i'm inserting it directly in the query. i don't know where is the problem, can anyone help me please and how can i make the js code work?
<?php
session_start();
include 'connect-db.php';
if(isset($_POST['sig'])){
$name=$_POST['name'];
$pass=$_POST['pass'];
$email=$_POST['email'];
$id=$_POST['id'];
$query= "INSERT INTO user (name, pass, e-mail, ID, role) VALUES ('$name', '$pass', '$email', $id, '1')";
$result=mysqli_query($con, $query);
if($result==1){
$status = "done";
}
else{
$status = "notdone";
}
header("Location: sign.php?status=$status");
exit();
}
?>
<html>
<head>
<?php include "log_header.php"?>
</head>
<script>
function cs(){
if(document.getElementById("cs").checked==true ){
document.getElementById("isco").style.display="none";
document.getElementById("cnco").style.display="none";
}
document.getElementById("csco").style.display="initial";
}
function is(){
if(document.getElementById("is").checked==true){
document.getElementById("csco").style.display="none";
document.getElementById("cnco").style.display="none";
}
document.getElementById("isco").style.display="initial";
}
function cn(){
if(document.getElementById("cn").checked==true ){
document.getElementById("isco").style.display="none";
document.getElementById("csco").style.display="none";
}
document.getElementById("cnco").style.display="initial";
}
</script>
<div style="background-color: white; text-align: left; padding-left:100px; padding-bottom: 10px">
<br><br><br>
<h3>Sign up</h3>
<form id="sign" name="sign" method="POST" action="sign.php">
<label for="name">Name: </label>
<br>
<input type="text" name="name" id="name" maxlength="10" required>
<br><br>
<label for="id">ID: </label>
<br>
<input type="text" name="id" id="id" maxlength="10" required>
<br><br>
<label for="pass">Password:</label>
<br>
<input type="password" name="pass" id="pass" maxlength="10" required >
<br><br>
<label for="email">Email: </label>
<br>
<input type="email" name="email" id="email" required>
<br><br>
<label for="major">Major:</label>
<input type="radio" name="major" id="cs" value="cs" onclick="cs()" >CS
<input type="radio" name="major" id="is" value="is" onclick="is()">IS
<input type="radio" name="major" id="cn" value="cn" onclick="cn()">CN
<br><br>
<div style="display: none;" id="csco">
<label for="courses">Select the courses you finished or takes currently: </label>
<br><br>
<input type="checkbox" name="courses" value="pr" >Professional Responsibility
<input type="checkbox" name="courses" value="se">Software Engineering
<input type="checkbox" name="courses" value="alg">Analysis and Design of Algorithms
<input type="checkbox" name="courses" value="web">Web-based Systems
<br>
</div>
<div style="display: none;" id="isco">
<label for="courses">Select the courses you finished or takes currently: </label>
<br><br>
<input type="checkbox" name="courses" value="web">Web-based Systems
<input type="checkbox" name="courses" value="sad">System Analysis and Design(2)
<br>
</div>
<div style="display: none;" id="cnco">
<label for="courses">Select the courses you finished or takes currently: </label>
<br><br>
<input type="checkbox" name="courses" value="np" >Introduction to Network Programming.
<input type="checkbox" name="courses" value="nd">Network Design or Network Simulation and Modeling.
<br>
</div>
<br>
<button name="sig" id="sig" style="padding: 10px" >Sign up</button>
</form>
</div>
<?php include "footer.php"?>
</body>
</html>
</div>