2011-07-31 10 views
0

안녕하세요, 저는 PHP 개발에 익숙합니다. Windows에서 wamp 서버를 사용하고 있습니다. php5.3.4, mysql5.1, apache2.2. 이 코드를 실행하려고하지만 error.php 페이지 만 있으면됩니다. 테이블에 auto_increment ids가있는 경우 mysql에 삽입하는 특별한 방법이 있습니까? 코드에서 ID에 NULL 값을 제공합니다.초보자 PHP MySQL 질문

제발 도와주세요. 내 멍청한 질문에 변명 해주세요.

function addMember($firstname, $lastname, $email, $password, $bday, $gender, $maritalStatus, $education, $occupation) { 
    $personalQ = "INSERT INTO users_personal_profile VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 
    if($stmt3 = $this->conn->prepare($personalQ)) { 
     $stmt3->bind_param('sssssssss', $firstname, $lastname, $email, $password, $bday, $gender, $education, $occupation, $maritalStatus); 
     $stmt3->execute(); 
     if($stmt3->fetch()) { 
      $stmt3->close(); 
      header("location: intermediate.php"); 
     } 
     else { 
      $stmt3->close(); 
      header("location: error.php"); 
     } 
    } 
} 
+0

사용'mysql_error를에 액세스 할 수 있습니다

을 (당신은. 그 동안 콘솔에서 phpMyAdmin을 또는 Navicat는 또는 SQL을 사용할 수 있습니다)'및 오류 확인 message ... 어떤 종류의 프레임 워크를 사용하고있는 것처럼 보입니다. – Sudantha

+3

['mysqli_stmt :: fetch'] (http://php.net/manual/en/mysqli-stmt.fetch.php)는 일반적으로 select 쿼리에 사용됩니다. 인덱스 쿼리가 있습니다. 문맥에 맞는 함수 만 사용하십시오. 대신'execute'가 반환하는 것을 확인하십시오. – hakre

+0

'INSERT'에서'fetch'가 리턴되어야하는 것은 무엇입니까? 나는 MySQL이'INSERT'로부터'RETURNING'을 지원하지 않는다고 생각합니다. 그래서'if ($ stmt3-> fetch())'를 테스트 할 때 항상 false로 평가됩니까? (hakre 말했다) –

답변

1

응축 코멘트 :

당신이 스크립트를 적용 할 수 무슨 일이 일어 났는지 알 수 있습니다 :

function addMember($firstname, $lastname, $email, $password, $bday, $gender, $maritalStatus, $education, $occupation) { 
    $personalQ = "INSERT INTO users_personal_profile VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 
    if($stmt3 = $this->conn->prepare($personalQ)) { 
     $stmt3->bind_param('sssssssss', $firstname, $lastname, $email, $password, $bday, $gender, $education, $occupation, $maritalStatus); 

     if($stmt3->execute()){ 
      $stmt3->close(); 
      header("location: intermediate.php"); 
     } 
     else { 
      echo $stmt3->error; 
      // header("location: error.php"); // can't output headers after outputting something, but it's just for debugging 
     } 
    } 
} 

이 실제 오류가 발생하고 무엇을 말하는 경우에 몇 가지 통찰력을 얻어야한다.

자동 누적 필드는 db 체계에서 설정해야합니다. 테이블은 어떻게 정의되어 있습니까? 첫 번째 필드가 실제로 자동 증가로 표시됩니까? (있는 경우 null이 작동해야합니다.) 또한 쿼리를 데이터베이스로 직접 실행하여 데이터베이스가 어떻게 작동하는지 확인할 수 있습니다.) 당신이 코드에서 자동 증가 값을해야하는 경우 ($mysqli_stmt->insert_id;

+0

그게 효과가 있습니다! fetch 문을 완전히 제거했습니다! Thanksa lot Inca .. 너는 나의 구세주 야 .. – Ari53nN3o