Jump to content

[SOLVED] Update?


Dat

Recommended Posts

I have this code that won't update anymore after I updated the form.

 

Help?

 

}elseif($_GET['edit'] == "anime"){

if($_POST['edit_submit']) {

	$id = $_POST['id'];
	$type = escape_data( $_POST['type'] );
	$title = escape_data( $_POST['title'] );
	$titlejap = escape_data( $_POST['japtitle'] );
	$image= escape_data( $_POST['image'] );
	$genres = escape_data( $_POST['genres'] );
	$formats = escape_data( $_POST['formats'] );
	$episode_number = escape_data( $_POST['episode_number'] );
	$length = escape_data( $_POST['length'] );
	$year = escape_data( $_POST['year'] );
	$opening = escape_data( $_POST['opening'] );
	$ending = escape_data( $_POST['ending'] );
	$summary = escape_data( $_POST['summary'] );
	$episode = escape_data( $_POST['episode'] );
	$review = escape_data( $_POST['review'] );
	$s_author = escape_data( $_POST['s_author'] );
	$r_author = escape_data( $_POST['r_author'] );
	$last_updated = date("Y-m-d");

		//Check if any fields are empty or not
		if((empty($title)) OR (empty($summary))) {
			echo "<center><b>Please fill in all required fields!</b></center>";

		} else {
		echo "type: $type<br><br>title: $title<br><br> summary: $summary<br><br> episodes: $episode<br>";
    		//The MySQL query which will update the content in the table.
    		$query = "UPDATE anime_reviews SET type = '$type', title = '$title', title_jap = '$titlejap', image = '$image', genres = '$genres', formats = '$formats', episode_number = '$episode_number', length = '$length', released = '$year', opening_t = '$opening', ending_t = '$ending', summary = '$summary', review = '$review', s_author = '$s_author', r_author = '$r_author', episodes = '$episode', last_updated = '$last_updated' WHERE id = '$id'";
    			//Execute the query.
    			$result = mysql_query($query) or die(mysql_error());
    			echo '<meta http-equiv="Refresh" content="10; URL=/" />The entry has been edited, please wait a few seconds (3) while I redirect you.<br> if not then click <a href="/">here!</a>';

	}
} elseif($_GET['id']) {
    	//Get the id
    	$id = $_GET['id'];
    	//Get entry based on id
    	$query = "SELECT * FROM anime_reviews WHERE ID='$id'";
    	$result = mysql_query($query) or die(mysql_error());
    	while ($row = mysql_fetch_array($result)) {
    		extract($row);
    		//Transform them into html special charactors
    		$title = htmlspecialchars($title);
    		$japtitle = htmlspecialchars($title_jap);
    		$image = htmlspecialchars($image);
    		$summary = htmlspecialchars($summary);
    		$genres = htmlspecialchars($genres);
    		$formats = htmlspecialchars($formats);
    		$episode_number = htmlspecialchars($episode_number);
    		$length = htmlspecialchars($length);
    		$year = htmlspecialchars($released);
    		$opening = htmlspecialchars($opening_t);
    		$ending = htmlspecialchars($ending_t);
    		$episode = htmlspecialchars($episodes);
    		$review = htmlspecialchars($review);
		$s_author = htmlspecialchars($s_author);
		$r_author = htmlspecialchars($r_author);
		$type = htmlspecialchars($type);
    		//Now the form!
?>

<form action="" method="post">
<table class="editor" border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td>*Type:</td>
    <td><select name="type" class="INPUT_type">
      <option value="anime" <?php if($type == "anime") { echo "selected"; } ?>>Anime</option>
      <option value="yaoi" <?php if($type == "yaoi") { echo "selected"; } ?>>Yaoi</option>
      <option value="yuri" <?php if($type == "yuri") { echo "selected"; } ?>>Yuri</option>
      <option value="movie" <?php if($type == "movie") { echo "selected"; } ?>>Movie</option>
    </select></td>
  </tr>
  <tr>
    <td>*Title:</td>
    <td><input class="INPUT_title" type="text" name="title" <?php echo "value=\"".$title."\""; ?>></td>
  </tr>
  <tr>
    <td>Japanese Title</td>
    <td><input class="INPUT_japtitle" type="text" name="japtitle" <?php echo "value=\"".$japtitle."\""; ?>></td>
  </tr>
  <tr>
    <td>Image:</td>
    <td><input class="INPUT_image" type="text" name="image" <?php echo "value=\"".$image."\""; ?>></td>
  </tr>
  <tr>
    <td>Genres:</td>
    <td><input class="INPUT_genres" type="text" name="genres" <?php echo "value=\"".$genres."\""; ?>></td>
  </tr>
  <tr>
    <td>Formats:</td>
    <td><input class="INPUT_formats" type="text" name="formats" <?php echo "value=\"".$formats."\""; ?>></td>
  </tr>
  <tr>
    <td>Number of Episodes:</td>
    <td><input class="INPUT_episodes" type="text" name="episode_number" <?php echo "value=\"".$episode_number."\""; ?>></td>
  </tr>
  <tr>
    <td>Length:</td>
    <td><input class="INPUT_length" type="text" name="length" <?php echo "value=\"".$length."\""; ?>></td>
  </tr>
  <tr>
    <td>Year(s) Published:</td>
    <td><input class="INPUT_year" type="text" name="year" <?php echo "value=\"".$year."\""; ?>></td>
  </tr>
  <tr>
    <td>Opening Theme Song(s):</td>
    <td><textarea class="INPUT_opening" type="text" name="opening"><?php echo "$opening"; ?></textarea></td>
  </tr>
  <tr>
    <td>Ending Theme Song(s):</td>
    <td><textarea class="INPUT_ending" type="text" name="ending"><?php echo "$ending"; ?></textarea></td>
  </tr>
  <tr>
    <td>*Summary:</td>
    <td><textarea class="INPUT_summary" type="text" name="summary"><?php echo "$summary"; ?></textarea></td>
  </tr>
  <tr>
    <td>*Summary's author:</td>
    <td><input class="INPUT_s_author" type="text" name="s_author" <?php echo "value=\"".$s_author."\""; ?>></td>
  </tr>
  <tr>
    <td>Review:</td>
    <td><textarea class="INPUT_review" type="text" name="review"><?php echo "$review"; ?></textarea></td>
  </tr>
  <tr>
    <td>Review's author:</td>
    <td><input class="INPUT_s_review" type="text" name="s_review" <?php echo "value=\"".$r_author."\""; ?>></td>
  </tr>
  <tr>
    <td>Episodes titles:</td>
    <td><textarea class="INPUT_episode" type="text" name="episode"><?php echo "$episode"; ?></textarea></td>
  </tr>
  <tr>
    <td colspan="2"><input class="INPUT_submit" type="submit" name="edit_submit" value="Update!"></td>
    </tr>
</table>
</form>

<?
	}
} else {
	$query = "SELECT * FROM anime_reviews ORDER BY title ASC";
	$result = mysql_query($query) or die(mysql_error());
	while ($row = mysql_fetch_array($result)) {
		extract($row);
		$summary = substr($summary, 0, 300);
		$japan = $title_jap;
		echo "<div align=\"left\"><a href=\"?edit=anime&id=$id\"><b>$title </b></a> - ";
			if ($japan){
				echo "($japan)";
			}
		echo "<br><small>Summary written by <i>$s_author</i></small><br><br>$summary...<br>
		<strong><a href=\"?delete=$id&type=anime\">DELETE</a></strong><hr align=\"left\" width=\"40%\" size=\"1\" />";
	}
}

 

Link to comment
Share on other sites

No error message it goes through as if it was successful.

It has worked before I updated the form but I might have made a mistake as well when I was updating the php code

 

action="" because it goes to itself.

 

You need to give it an action

 

make it, <?php echo $_SERVER['PHP_SELF']; ?>

 

if($_POST['edit_submit']) { << it will not get posted without an action, thats why it doesnt update with the new values..

Link to comment
Share on other sites

No error message it goes through as if it was successful.

It has worked before I updated the form but I might have made a mistake as well when I was updating the php code

 

action="" because it goes to itself.

 

You need to give it an action

 

make it, <?php echo $_SERVER['PHP_SELF']; ?>

 

if($_POST['edit_submit']) { << it will not get posted without an action, thats why it doesnt update with the new values..

 

when you dont define the page where to take an action the default is the self page ! same as php self

Link to comment
Share on other sites

Somehow what you say makes sense but I don't think it matters because I have another form and it's the same... but it works...

 

This my manga update part (BTW add, update, delete, codes are all on one page: index.php):

 

}elseif($_GET['edit'] == "manga"){

if($_POST['edit_submit']) {

	$id = $_POST['id'];
	$title = escape_data( $_POST['title'] );
	$titlejap = escape_data( $_POST['japtitle'] );
	$image= escape_data( $_POST['image'] );
	$genres = escape_data( $_POST['genres'] );
	$formats = escape_data( $_POST['formats'] );
	$volume_number = escape_data( $_POST['volume_number'] );
	$author = escape_data( $_POST['author'] );
	$year = escape_data( $_POST['year'] );
	$summary = escape_data( $_POST['summary'] );
	$review = escape_data( $_POST['review'] );
	$s_author = escape_data( $_POST['s_author'] );
	$r_author = escape_data( $_POST['r_author'] );
	$last_updated = date("Y-m-d");

		//Check if any fields are empty or not
		if((empty($title)) OR (empty($summary))) {
			echo "<center><b>Please fill in all required fields!</b></center>";

		} else {
    		//The MySQL query which will update the content in the table.
    		$query = "UPDATE manga_reviews SET title = '$title', title_jap = '$titlejap', image = '$image', genres = '$genres', formats = '$formats', volume_number = '$volume_number', author = '$author', released = '$year', summary = '$summary', review = '$review', s_author = '$s_author', r_author = '$r_author', last_updated = '$last_updated' WHERE id = '$id'";
    			//Execute the query.
    			$result = mysql_query($query) or die(mysql_error());
    			echo '<meta http-equiv="Refresh" content="2; URL=/" />The entry has been edited, please wait a few seconds (3) while I redirect you.<br> if not then click <a href="/">here!</a>';

	}
} elseif($_GET['id']) {
    	//Get the id
    	$id = $_GET['id'];
    	//Get entry based on id
    	$query = "SELECT * FROM manga_reviews WHERE ID='$id'";
    	$result = mysql_query($query) or die(mysql_error());
    	while ($row = mysql_fetch_array($result)) {
    		extract($row);
    		//Transform them into html special charactors
    		$title = htmlspecialchars($title);
    		$japtitle = htmlspecialchars($title_jap);
    		$image = htmlspecialchars($image);
    		$summary = htmlspecialchars($summary);
    		$genres = htmlspecialchars($genres);
    		$formats = htmlspecialchars($formats);
    		$volume_number = htmlspecialchars($volume_number);
    		$year = htmlspecialchars($released);
    		$review = htmlspecialchars($review);
    		$author = htmlspecialchars($author);
		$s_author = htmlspecialchars($s_author);
		$r_author = htmlspecialchars($r_author);
    		//Now the form!
?>

<form action="" method="post">
	Title: <input name="title" type="text" value="<?php echo "$title"; ?>" size="30" />
	<br>
	Japanese Title: <input name="japtitle" type="text" value="<?php echo "$japtitle"; ?>" size="50" />
	<br>
	Summary: <textarea cols="45" name="summary" rows="10"><?php echo "$summary"; ?></textarea>
	<br>
	Summary's author: <input type="text" name="s_author" value="<?php echo "$s_author"; ?>">
	<br>
	Review: <textarea name="review" cols="50" rows="10"><?php echo "$review"; ?></textarea>
	<br>
	Review's author: <input type="text" name="r_author" value="<?php echo "$r_author"; ?>">
	<br>
	Image: <input type="text" name="image" value="<?php echo "$image"; ?>"/>
	<br>
	Genres: <textarea cols="45" rows="5" name="genres"><?php echo "$genres"; ?></textarea>
	<br>
	Formats: <input name="format" type="text" value="<?php echo "$formats"; ?>" size="40">
	<br>
	Number of Volumes: <input type="text" name="volume_number" value="<?php echo "$volume_number"; ?>"/>
	<br>
	Author: <input type="text" name="author" value="<?php echo "$author"; ?>" />
	<br>
	Year Published: <input type="text" name="year" value="<?php echo "$year"; ?>" />
	<br>
	<input type="hidden" name="id" value="<?php echo "$id"; ?>" />
	<input type="submit" name="edit_submit" value="Update" />
</form>
<?
	}
} else {
	$query = "SELECT * FROM manga_reviews ORDER BY title ASC";
	$result = mysql_query($query) or die(mysql_error());
	while ($row = mysql_fetch_array($result)) {
		extract($row);
		$summary = substr($summary, 0, 300);
		$japan = $title_jap;
		echo "<div align=\"left\"><a href=\"?edit=manga&id=$id\"><b>$title </b></a> - ";
			if ($japan){
				echo "($japan)";
			}
		echo "<br><small>Summary written by <i>$s_author</i></small><br><br>$summary...<br>
		<strong><a href=\"?delete=$id&type=manga\">DELETE</a></strong><hr align=\"left\" width=\"40%\" size=\"1\" />";
	}
}

 

Link to comment
Share on other sites

I would do what phpSensei says.

 

Your form doesn't have a field called "edit" and so this statement:

 

}elseif($_GET['edit'] == "manga"){

 

will not be true when form is submitted - only when the link is clicked. So, logic doesn't go into the update section that you show.

 

You need to put displays/echo's for debugging to help yourself debug this problem. Take members advice otherwise this thread will end up being very long.

 

Everyone, try to always use this forums code tags when posting code here.

 

http://us2.php.net/manual/en/tutorial.forms.php

 

Link to comment
Share on other sites

I think you guy's are thinking out of the box here, I'm giving SOME of the code... the part where I altered something and something went wrong...

 

I mean if I didn't know what I was doing why would I type in }elseif($_GET['edit'] == "anime"){

 

and I probably should have explained that the once I press "update"

 

it executes this code: (I added in an echo and it output's what I have put in the form, so assuming the form work's.. I pretty sure it something else than the form)

if($_POST['edit_submit']) {

 

$id = $_POST['id'];

$title = escape_data( $_POST['title'] );

$titlejap = escape_data( $_POST['japtitle'] );

$image= escape_data( $_POST['image'] );

$genres = escape_data( $_POST['genres'] );

$formats = escape_data( $_POST['formats'] );

$volume_number = escape_data( $_POST['volume_number'] );

$author = escape_data( $_POST['author'] );

$year = escape_data( $_POST['year'] );

$summary = escape_data( $_POST['summary'] );

$review = escape_data( $_POST['review'] );

$s_author = escape_data( $_POST['s_author'] );

$r_author = escape_data( $_POST['r_author'] );

$last_updated = date("Y-m-d");

 

//Check if any fields are empty or not

if((empty($title)) OR (empty($summary))) {

echo "<center><b>Please fill in all required fields!</b></center>";

 

} else {

echo $summary;

    //The MySQL query which will update the content in the table.

    $query = "UPDATE manga_reviews SET title = '$title', title_jap = '$titlejap', image = '$image', genres = '$genres', formats = '$formats', volume_number = '$volume_number', author = '$author', released = '$year', summary = '$summary', review = '$review', s_author = '$s_author', r_author = '$r_author', last_updated = '$last_updated' WHERE id = '$id'";

    //Execute the query.

    $result = mysql_query($query) or die(mysql_error());

    echo '<meta http-equiv="Refresh" content="2; URL=/" />The entry has been edited, please wait a few seconds (3) while I redirect you.<br> if not then click <a href="/">here!</a>';

 

}

 

Link to comment
Share on other sites

I mean if I didn't know what I was doing why would I type in }elseif($_GET['edit'] == "anime"){

 

That's just the thing, we don't know your level of expertise and we don't know your whole code.

 

You're really not telling us much. What is EXACTLY wrong? Well, do you see the entry has been edited message or not?

 

If you haven't already done it, display the $query, and take that SQL and run it out side of PHP to see if it works.

 

Are you really changing any of the fields or just trying to update the same stuff?  

 

MySQL will not update a row when the data is the same (something has to actually be different).

 

 

FYI - It's best to use || instead of OR on this line:

 

if((empty($title)) OR (empty($summary))) {

 

 

Also, you don't seem to be taking advice. So, why should I or members keep bothering to help you? Put in an action value.

 

 

 

Link to comment
Share on other sites

Hmm, just learn something today that I have never thought of doing.

 

I echo'ed the query and it came out (positive) (Correct) with the edit's and stuff, the data that's SUPPOSE to be updated! BUT it's not updating...

 

So... I'm thinking.. WTH !? And so... I sat and slapped myself a couple times before continue typing...

There was a missing tag in the form:

<input type="hidden" name="id" value="<?php echo "$id"; ?>" />

There was no id set to tell what to update! :o The person to thank here is "toplay" thanks, I'm kinda starting to like this forum, fast replies.

 

BTW when I add index.php to the action it doesn't do anything but go straight to the page without action

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.