2012-11-28 3 views
1

TV 프로젝트의 백 패널을 만들려고합니다. 내 MySql 데이터베이스는 두 개의 테이블로 구성됩니다. "쇼"& "계절".업데이트 기록 TV 쇼 데이터베이스 - PHP MYSQL

쇼 테이블은 ID 표시 (기본 키), 쇼 제목 & 날짜로 구성됩니다. 시즌 표는 시즌 ID (기본 키), 쇼 ID (외래 키), 시즌, 출시 날짜로 구성됩니다.

제어판에서 가장 먼저 보는 것은 데이터베이스의 모든 프로그램을 테이블 형식으로 보는 것입니다. 예를 들어 "Dexter"를 편집하면 편집 페이지로 이동하여 dexter 시즌의 입력란을 볼 수 있습니다. 시즌 1, 시즌 2와 마찬가지로 ... 나는 이런 종류의 일을합니다. 그 말은 입력 상자에 제대로 표시된다는 의미지만, 제출하면 동일한 편집 페이지로 리다이렉트되며 아무 것도 업데이트되지 않습니다.

편집 할 수 있습니다 내 주요 index.php를 백패널에서 코드 :

<td><a href="edit.php?id=<?php echo $row['show_id']; ?>">edit</a></td> 

코드 edit.php에서 : 당신은 아마 궁금해하는

<?php 
$playlist_id=$_GET['id']; 
// this makes it so it grabs the season records that match the show id 
$sql="SELECT * FROM seasons WHERE show_id='$show_id'"; 
$result=mysql_query($sql); 
$count=mysql_num_rows($result); 
?> 



<table> 
<form name="form1" method="post" action=""> 
<tr> 
<td> 
<table> 
<tr> 
<td align="center"><strong>Id</strong></td> 
<td align="center"><strong>Season Name</strong></td> 
</tr> 

<?php 
while($rows=mysql_fetch_array($result)){ 
?> 

<tr> 
<td align="center"> 
<input name="season_id[]" type="text" id="season_id" value="<?php echo $rows['season_id']; ?>"> 
</td> 
<td align="center"> 
<input name="Season[]" type="text" id="Season" value="<?php echo $rows['Season']; ?>"> 
</td> 
</tr> 

<?php 
} 
?> 

<tr> 
<td></td> 
<td></td> 
<td colspan="4" align="right"><input type="Submit" name="Submit" value="Submit"></td> 
</tr> 
</table> 
</td> 
</tr> 
</form> 
</table> 

<?php 

$result1 = FALSE; 
if (isset($_GET['Submit'])) { 
for($i=0;$i<$count;$i++){ 
$sql1="UPDATE seasons SET Season='$Season[$i] WHERE Season_id='$Season_id[$i]'"; 
$result1=mysql_query($sql1); 
} 
} 

if($result1){ 
header("location:update.php"); 
} 
mysql_close(); 
?> 

는 이유는 무엇을 편집 할 것 계절의 이름 그러나 나는 결국이 장애물을 지나면 더 복잡하게하고 더 많은 분야를 추가 할 것이다. 내가 올바르게 말했듯이,하지만 내가 제출을 누르면 그냥 페이지를 다시로드하고 아무것도 바뀌지 않는다. 이는 isset을 변경해야하므로

답변

0

당신은, 데이터를 게시하는 ($는 _ [ '제출'] GET)

당신은 업데이트 쿼리에서 오류가 ($ _ POST는 [ '제출'])는 isset합니다. '$ Season [$ i] 이후에 누락되었습니다.

$ sql1 = "UPDATE seasons SET Season ='$ Season [$ i] 'WHERE Season_id ='$ Season_id [$ i] '";

mysql_affected_rows()를 사용하여 행이 업데이트되었는지 확인할 수 있습니다.

if(mysql_affected_rows() == 1){ 
echo "Updated"; 
} else { echo "error"; } 
+0

변경되었지만 여전히 페이지가 새로 고쳐지고 데이터베이스에 아무것도 제출되지 않았습니다. –

+0

나는 대답을 편집한다 –

+0

아직도 그 페이지를 새롭게하고있다. 만약 내가 다른 페이지에 SQL을 업데이 트하는 것이 더 쉬울 것이고 그렇다면 어떻게 다른 페이지에 넣을 까? 나는 내가 할 수있는

그러나 내가 procupdate.php에 넣을 것이 무엇인지 안다. –

0

페이지가 게시 될 때 쿼리를 수행하려고합니다. 당신은 페이지는 다음과 같이한다 edit.php :

<?php 
if (isset($_POST['submit'])) { 
    $sql = "UPDATE `table_name` (`column1`, `column2`) VALUES (:value1, :value2)"; 
    $statement = $pdo->prepare($sql); 
    $statement->bindParam(':value1', $_POST['some_field_name']); 
    $statement->bindParam(':value1', $_POST['some_field_name']); 
    $statement->execute(); 
    // record's updated; either redirect or display error message 
} 
?> 
<!-- HTML of form here; will be shown if nothing’s been POSTed --> 

이 경우 "제출"당신의 제출 버튼의 이름, 즉 <input type="submit" name="submit" value="Update" />입니다.

mysql_ 함수가 아닌 PDO과 같은 함수를 사용해야합니다.이 함수는 현재 사용되지 않습니다.