2013-03-14 3 views
0

mysql 데이터베이스에 데이터를 삽입하는 중 문제가 발생했습니다. 오류는 다음과 같이 나타났다되어 는 "당신은 당신의 SQL 구문에 오류가있다; 근처 사용할 수있는 권리 구문에 대한 MySQL 서버 버전에 해당하는 설명서를 확인를 '1') '라인 1에서"MYSQL 삽입 데이터

<?php 


    $firstname = $_POST['firstname']; 
    $lastname = $_POST['lastname']; 
    $fathername = $_POST['fathername']; 
    $mothername = $_POST['Firstname']; 
    $fatherjob = $_POST['fatherjob']; 
    $motherjob = $_POST['motherjob']; 
    $phone = $_POST['phone']; 
    $mobile1 = $_POST['mobile1']; 
    $mobile2 = $_POST['mobile2']; 
    $address = $_POST['address']; 
    $id=1; 
    $roll=1; 

    $sex = $_POST['sex']; 
    $bloodgroup = $_POST['bloodgroup']; 
    $class = $_POST['class']; 
    $section = $_POST['section']; 
    $day = $_POST['day']; 
    $month = $_POST['month']; 
    $year = $_POST['year']; 
    $birthday=$day."-".$month."-".$year; 


    $hostname_localhost ="localhost"; 
    $database_localhost ="school"; 
    $username_localhost ="root"; 
    $password_localhost =""; 
    $localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost) 
    or 
    trigger_error(mysql_error(),E_USER_ERROR); 

    mysql_select_db($database_localhost, $localhost); 

    $sql = "INSERT INTO student_info VALUES ('".$id."',".$firstname."','".$lastname."','".$sex."','".$bloodgroup."','".$fathername."','".$mothername ."','".$fatherjob."','".$motherjob."','".$address."','".$birthday."','".$phone."','".$mobile1."','".$mobile2."','".$class."','".$section."','".$roll."')"; 

    mysql_query($sql) or die(mysql_error()); 
    echo "updated succesfully"; 

?> 

BTW, 나는 id와 roll이라는 이름의 테이블에 2 열을 자동으로 생성해야합니다 ...이 경우에는 올바른 sql입니까?

답변

0

가장 좋은 방법은 당신의 당신은 여기에서 실수를 한

$sql = "INSERT INTO student_info (id, firstname, .....) VALUES ('".$id."',".$firstname."','".$lastname."','".$sex."','".$bloodgroup."','".$fathername."','".$mothername ."','".$fatherjob."','".$motherjob."','".$address."','".$birthday."','".$phone."','".$mobile1."','".$mobile2."','".$class."','".$section."','".$roll."')"; 
1

은 YES 구문 권리 구문은 오류 거기는 .. 당신이 그것을에 삽입 할 지정된 필드가

$sql = "INSERT INTO (id,firstname) VALUES (1,'Oussaki')"; 

에 대한 모든 행운

-1

,536 : 경우는 다음과 같은 열을 언급 쿼리를 사용하는 것입니다
$sql = "INSERT INTO student_info VALUES ('".$id."',".$firstname."','".$lastname."','".$sex."','".$bloodgroup."','".$fathername."','".$mothername ."','".$fatherjob."','".$motherjob."','".$address."','".$birthday."','".$phone."','".$mobile1."','".$mobile2."','".$class."','".$section."','".$roll."')"; 

MYSQL에 데이터를 삽입하려면 먼저 어떤 column을 삽입하고 어떤 값을 사용해야하는지 확인해야합니다. 따라서 VALUES을 선언하기 전에 먼저 $id $firstname을 저장하려는 열을 지정해야합니다. 다른 사람에게도 마찬가지입니다.

또한 $id과 그 전후에 "점"이 필요하지 않습니다. 데이터베이스에 id firstname 등의 열이 있기를 바랍니다. 예를 들어

올바른 코드

$sql = "INSERT INTO student_info (id,firstname) VALUES ('$id',$firstname'); 
관련 문제