-1

I cant seem to insert to table students please help... I get data input failed. Is there something wrong with my query? or a mismatch with the data types in my table?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Student Evaluation Form</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>

</head>
<body id="main_body" >
<?php

include 'C:\xampp\htdocs\Student_evaluation\functions.php';

if(isset($_POST['submit']))
{
//get data
$name = $_POST['name'];
$f_lastname = $_POST['f_lastname'];
$second_lastname = $_POST['second_lastname'];
$student_number = $_POST['student_number'];
$semester_year = $_POST['semester_year'];
$course = $_POST['course'];
$section = $_POST['section'];
$grade = $_POST['grade'];
$student_perform = $_POST['student_perform'];
$comment_box = $_POST['comment_box'];

$sql = "INSERT INTO `students`(`name`, `first_lastname`, `second_lastname`, `numero_estudiante`, `semester`, `course`, `section`, `f_grade`, `students_perform`, `comments`) 
VALUES ('$name','$f_lastname','$second_lastname','$student_number','$semester_year','$course','$section','$grade','$student_perform','$comment_box')";

$con = mysqli_connect("localhost","root","");
$result = mysqli_query($con, $sql);

if($result) {
    echo("<br>Data Input OK");
} else {
    echo("<br>Data Input Failed");
}

}


?>

    <img id="top" src="top.png" alt="">
    <div id="form_container">

        <h1><a>Student Evaluation Form</a></h1>
        <form id="form_801787" class="appnitro"  method="POST" action="form.php">
                    <div class="form_description">
            <h2>Student Evaluation Form</h2>
            <p></p>
        </div>                      
            <ul >

                    <li id="li_1" >
        <label class="description" for="element_1">Student Information </label>
        <span>
            <input id="element_1_1" name= "name" class="element text" maxlength="255" size="8"/>
            <label>Name</label>
        </span>
        <span>
            <input id="element_1_2" name= "f_lastname" class="element text" maxlength="255" size="14" />
            <label>First Lastname</label>
        </span>
        <span>
            <input id="element_1_2" name= "second_lastname" class="element text" maxlength="255" size="14"/>
            <label>Second Lastname</label>
        </span> 
        <span>
            <input id="element_1_2" name= "student_number" class="element text" maxlength="255" size="14"/>
            <label>Student Number</label>
        </span> 
        </li>       <li id="li_4" >
        <label class="description" for="element_4">Semester </label>
        <div>
        <select class="element select medium" id="element_4" name="semester_year"> 
            <option value="1" selected="selected">Select one</option>
<option value="August 2014" >August 2014</option>
<option value="January 2015" >January 2015</option>
<option value="Summer 2015" >Summer 2015</option>
<option value="August 2015" >August 2015</option>

        </select>
        </div> 
        </li>       <li id="li_8" >
        <label class="description" for="element_8">Course </label>
        <div>
        <select class="element select medium" id="element_8" name="course"> 
            <option value="" selected="selected"></option>
<option value="1" >Select one</option>
<option value="COMP 2110" >COMP 2110</option>
<option value="COMP 2120" >COMP 2120</option>
<option value="GEIC 1010" >GEIC 1010</option>

        </select>
        </div> 
        </li>       <li id="li_5" >
        <label class="description" for="element_5">Section </label>
        <div>
            <input id="element_5" name="section" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_6" >
        <label class="description" for="element_6">Final Grade Percentage </label>
        <div>
            <input id="element_6" name="grade" class="element text medium" type="text" maxlength="255" value=""/> 
        </div><p class="guidelines" id="guide_6"><small>Example: 95</small></p> 
        </li>       <li id="li_9" >
        <label class="description" for="element_9">How was the students performance during the course? </label>
        <span>
            <input id="element_9_1" name="student_perform" class="element radio" type="radio" value="Superior Performance" />
<label class="choice" for="element_9_1">Superior Performance</label>
<input id="element_9_2" name="student_perform" class="element radio" type="radio" value=">Good Performance" />
<label class="choice" for="element_9_2">Good Performance</label>
<input id="element_9_3" name="student_perform" class="element radio" type="radio" value="Poor Performance" />
<label class="choice" for="element_9_3">Poor Performance</label>

        </span> 
        </li>       <li id="li_7" >
        <label class="description" for="element_7">Additional comments </label>
        <div>
            <textarea id="element_7" name="comment_box" class="element textarea medium"></textarea> 
        </div> 
        </li>

                    <li class="buttons">
                <input type="hidden" name="form_id" value="801787" />

                <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
        </li>
            </ul>
        </form> 
    </div>
    <img id="bottom" src="bottom.png" alt="">
    </body>
</html>
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
John Vega
  • 15
  • 1
  • 7
  • 1
    You need to select a DB also not just connecting to mysql http://in1.php.net/mysqli_select_db – Abhik Chakraborty Mar 16 '14 at 19:43
  • Start by echoing the value of $sql so you can see the query being generated. Then, run this query manually against MySQL to identify any problems. – Brent Robinson Mar 16 '14 at 19:43
  • Read [How can I prevent SQL injection in PHP?](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1) – user2864740 Mar 16 '14 at 19:44
  • Also search for "mysqli error handling". The code doesn't bother to log/report the actual error message, which would *say* why it isn't working. "Data Input Failed" is near-meaningless to diagnose such questions. – user2864740 Mar 16 '14 at 19:50

1 Answers1

1

Maybe you are not selecting the db where the query should be inserted

You should use something like this

mysqli_select_db($con,"test");

where test is the database you want to select

also you can replace you $con with this

$con=mysqli_connect("localhost","user","password","db");

in this case, the last parameter represents the db

slozano95
  • 278
  • 7
  • 22