I’m trying to create a backpanel to my TV project. My MySql database consists of two tables. “Shows” & “Seasons”.
The Shows table consists of the Show ID (Primary Key), Show Title & date. The Seasons table consists of Season ID (Primary Key), Show ID (Foreign Key), Season, release date.
The first thing you see in the control panel is all the shows from the database in table format. For instance if you edit “Dexter” it will bring you to the edit page showing input boxes for the seasons of dexter. Like Season 1,Season 2 etc… I have this sort of working. By that i mean it displays properly in input boxes but when i go to submit it just redirects back to the same edit page and nothing gets updated.
The Code from my main index.php backpanel that allows you to edit:
<td><a href="edit.php?id=<?php echo $row['show_id']; ?>">edit</a></td>
Code from 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();
?>
You are probably wondering why would i want to edit the name of the seasons but i will eventually make it more complicated and add more fields once i get past this hurdle. Like i said it displays properly but when i hit submit it just reloads the page and nothing changes.
You are posting data, so you need to change this isset($_GET[‘Submit’]) to isset($_POST[‘Submit’])
You have error in update query. Missing ‘ after $Season[$i]
$sql1=”UPDATE seasons SET Season=’$Season[$i]’ WHERE Season_id=’$Season_id[$i]'”;
You can use mysql_affected_rows() to check if row has updated.