2016-09-26 3 views
-1

MySQL에 데이터를 삽입하려고하는데 작동하지 않습니다. 이 코드에는 오류가 표시되지 않습니다.MySQL에 데이터를 삽입하려고하는데 오류가 없지만 데이터가 삽입되지 않습니까?

<?php 

$connection = mysqli_connect("localhost", "root", ""); 
if(!$connection) { 
    echo 'Server Not Found'; 
} 
else { 
    echo 'Server Found'; 
} 

// Establishing Connection with Server 
$db = mysqli_select_db($connection,"colleges"); // Selecting Database from Server 
if (!$db) { 
    echo 'Databaje Not Found'; 
} 
else { 
    echo 'Databaje found'; 
} 

if(isset($_POST['submit'])) { // Fetching variables of the form which travels in URL 
    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $contact = $_POST['contact']; 
    $address = $_POST['address']; 

    if($name !=''||$email !='') { 
     //Insert Query of SQL 
     $query = mysqli_query("insert into students(student_name, student_email, student_contact,student_adress) values ('$name', '$email', '$contact', '$address')", $connection); 

     echo "<br/><br/><span>Data Inserted successfully...!!</span>"; 
    } 
    else { 
     echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>"; 
    } 
} 

mysqli_close($connection); // Closing Connection with Server 

?> 
+1

응답으로 나타나는 에코 메시지는 무엇입니까? – Ma3x

+0

'student_adress'는'student_address' 여야합니다. – Carl

+1

$ 연결은 mysqli_query()에 먼저옵니다. – nogad

답변

0

$ 쿼리에서 $ 연결을 먼저 작성한 다음 쉼표를 추가하여 삽입 쿼리를 작성하십시오. 도움이 될 것입니다. 또한 $ query가 여전히 실패 할 경우 mysqli_error() 함수를 사용하여 쿼리의 오류를 확인하십시오.

관련 문제