2011-04-12 2 views
0

코드를 사용하여 :이 테이블을 업데이트하는 방법? "INC/Q/prof.php"에 PHP/MySQL의

<?php 
// Insert Comments into Database that user provides 
$comm = mysql_real_escape_string($_POST['addComment']); 

// following line has changed: 
$pID4 = filter_var($_POST['pID'], FILTER_SANITIZE_STRING); 

$commentDetail = $_POST['addComment']; 
$username = "###"; 
$password = "###"; 
$pdo4 = new PDO('mysql:host=localhost;dbname=####', $username, $password); 
$pdo4->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
$sth4 = $pdo4->prepare(' 
INSERT INTO Comment (info, pID, cID) VALUES(?,?,?) 
SELECT Comm.cID 
FROM Professor P, Comment Comm, Course Cou 
WHERE P.pID = Comm.pID 
AND Cou.cID = Comm.cID; 
'); 
$sth4->execute(array($commentDetail, $pID4, $cID)); 


?> 

HTML

<form action='inc/q/prof.php' method='post'> 
        <input type='text' id='addComment' name='addComment' tabindex='3' value='Enter comment' /> 
       <input type='hidden' name='pID' value='<?php echo $pID4; ?>'> 

       </form> 

테이블 : comm course prof

오류가 계속 수신 됨 - 여전히 오류가 발생합니다. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT Comm.cID FROM Professor P, Comment Comm, Course Cou WHERE P.pID = Comm.p' at line 2\PDOStatement->execute(Array) #1

답변

0

숨겨진 입력 필드로 전달할 수 있습니다. 또한

<input type="hidden" name="pID" value="<?php echo $pID4 ?>" /> 

, 실제로 올바른 필드와 값을 게시하는 확인 : 그것은 당신이 이미 pID에 대한 것을 가지고있는 것처럼 보인다. prof.php의 맨 위에 다음을 추가

print_r($_POST); 

내 생각 엔이 $_POST['pID']

+0

이렇게하면 Array()가됩니다. 업데이트 된 코드를 참조하십시오. – Jshee

0

에 대한 사실 전달하지 아무거나 그것은 URL을 삭제 함께 할 수 없다; 숨겨진 필드에 pID를 삽입하는 메아리가 끝나면 세미콜론이 누락됩니다. 따라서 PHP가 실행되지 않기 때문에 pID에 빈 값을 전달하는 것입니다. 또한 courseinfoDD 입력이 없으므로 새로운 행에 null을 입력하게됩니다.

+0

내 코드와 함께 사용중인 것을 확인할 수 있습니까? – Jshee

+0

코드도 업데이트됩니다. – Jshee

관련 문제