Jump to content

Update problem


livewirerules

Recommended Posts

When i try to update i get the success message but the database isn't getting updated.Can some one pls help me out with the reason why the database isn't getting updated

 

<?php include("adminnav.html");

$image="<img src=movie_images/".$row['image'] ."> <br>";

if (isset($_POST['edit'])) {


$NewImageSize = $_FILES['image']['size'];

if($NewImageSize > '0')
{
	$NewImage = ($_FILES['image']['name']);

	copy($_FILES['image']['tmp_name'], "../movie_images/$NewImage");
}

$sql="UPDATE movie_info SET
		title='$_POST[title]',
		director='$_POST[director]',
		writer='$_POST[writer]',
		image='$NewImage',
		date='$_POST[date]',
		cast='$_POST[cast]',
		plot='$_POST[plot]',
		otherinfo='$_POST[otherinfo]',
		download='$_POST[download]'

		WHERE id='$id'";
		$result=mysql_query($sql);
		if ($result) {
			?>
			<div align="center"><span class="red">Edit Success !!</span>
			<?php
		} else
		{
			echo "error ".mysql_error();
		}
		//echo "success";
		//header("Refresh:2;url=manage_movies.php");

}
?>	

Link to comment
Share on other sites

If the database is not being updated then I sugest you replace the line

$result=mysql_query($sql);  WITH  echo ($sql)  This will display the query on the page. You can examinit properly and copy it and paste it into the table directly. You might see an error this way.

 

Desmond.

 

Link to comment
Share on other sites

$id=$_GET['id'];

 

i tried echo ($sql) ,seems like the id isn't passing.I have 3 forms one to edit movies,news and members details.I have used the same code for all the pages but only the member edit page works.i have defined the get[id] for those pages.any reason why the id isnt passing??  and how do i fix it ..Im really a newbie for coding  ;D

 

Link to comment
Share on other sites

I tried it but doesn't work.First in the edit for i retrieve all the avalable dedails relevant for the id using the following code.

 

<?php
ob_start();
session_start();

include("../includes/conn.php");
include("auth.php");
include("header.html");
include("../val.js");

//$_SESSION['id']=$id;
//print ($id);

$sql="SELECT * FROM `movie_info` WHERE id='$_GET[id]'";
$result=mysql_query($sql) or die(mysql_error());


while ($row=mysql_fetch_array($result)) {
//$edit=$_POST['editmovie'];
$title=$row['title'];
$director=$row['director'];
$writer=$row['writer'];
$release=$row['date'];
$cast=$row['cast'];
$plot=$row['plot'];
$otherinfo=$row['otherinfo'];
$download=$row['download'];
$imageold="<img src=../movie_images/".$row['image'] ."> <br>";


}
?>

 

as it works without any problems.But i as mentioned in the first topic in my edit code the movie id isn't passing.Both the codes are in the same page.I already assingned the get id for a variable but but it doesnt pass it in the edit process.what is the reason?

Link to comment
Share on other sites

Could try a few things. First, try putting quote marks around the names in the brackets. eg. $_POST['title'].

 

Second, if $id is an integer, you could try altering the query, removing the quote marks around $id.

e.g. WHERE id='$id' becomes WHERE id=$id

 

Finally, I've used the sprinf function to update successfully in the past. Could try something like:

$sql = sprintf("UPDATE movie_info SET title='%s', director='%s', writer='%s', image='$NewImage', date='%s', cast='%s', plot='%s', otherinfo='%s', download='%s'

WHERE id='$id'",

$_POST['title'],

$_POST['director'],

$_POST['writer'],

$NewImage,

$_POST['date'],

$_POST['cast'],

$_POST['plot'],

$_POST['otherinfo'],

$_POST['download']);

 

 

Link to comment
Share on other sites

Here is my compleet code

 

<?php
ob_start();
session_start();

include("../includes/conn.php");
include("auth.php");
include("header.html");
include("../val.js");

//$_SESSION['id']=$id;
//print ($id);

$sql="SELECT * FROM `movie_info` WHERE id='$_GET[id]'";
$result=mysql_query($sql) or die(mysql_error());


while ($row=mysql_fetch_array($result)) {
//$edit=$_POST['editmovie'];
$title=$row['title'];
$director=$row['director'];
$writer=$row['writer'];
$release=$row['date'];
$cast=$row['cast'];
$plot=$row['plot'];
$otherinfo=$row['otherinfo'];
$download=$row['download'];
$imageold="<img src=../movie_images/".$row['image'] ."> <br>";


}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" href="../images/Underground.css" type="text/css" />			

<title>Underground</title>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>

<body>
<!-- wrap starts here -->
<div id="wrap">
<?php include("adminnav.html");

//$image="<img src=movie_images/".$row['image'] ."> <br>";

if (isset($_POST['edit'])) {

$NewImageSize = $_FILES['image']['size'];

if($NewImageSize > '0')
{
	$NewImage = ($_FILES['image']['name']);

	copy($_FILES['image']['tmp_name'], "../movie_images/$NewImage");
}
	else
{
	$NewImage = $imageold;
}

$sql="UPDATE movie_info SET
		title='$_POST[title]',
		director='$_POST[director]',
		writer='$_POST[writer]',
		image='$NewImage',
		date='$_POST[date]',
		cast='$_POST[cast]',
		plot='$_POST[plot]',
		otherinfo='$_POST[otherinfo]',
		download='$_POST[download]'

		WHERE id='$_GET[id]'";
		//$result=mysql_query($sql);
		echo  $sql;
		if ($result) {
			?>
			<div align="center"><span class="red">Edit Success !!</span>
			<?php
		} else
		{
			echo "error ".mysql_error();
		}
		//echo "success";
		//header("Refresh:2;url=manage_movies.php");

}
?>					
	<div id="main">				

		<a name="TemplateInfo"></a>
		<h1>Edit movie </h1>

		<p><strong>Edit movies </strong></p>
		<?php echo $title; ?>

		</p>
		<form action="editmovie.php" method="POST" name="f1" enctype="multipart/form-data" OnSubmit="return CheckAddMovie()">
              <p>Title                
                  <input name="title" type="text" id="title" value="<?php echo $title; ?>"size="40" />
              </p>
		  <p>Director          
                  <input name="director" type="text" id="director" value="<?php echo $director; ?>"size="40" />
              </p>
		  <p>Writer             
                  <input name="writer" type="text" id="writer" value="<?php echo $writer; ?>" size="40" />
              </p>
		  <p>Current Image     
                  <?php echo "$imageold"; ?>
              </p>
              <p>Add New Image     
                  <input name="image" type="file" size="40" />
              </p>
		  <p>Release date  
                  <input name="date" type="text" id="date" value="<?php echo $release; ?>" size="20" />
              </p>
		  <p>Cast                
                  <textarea name="cast" cols="40"  rows="5" id="cast" ><?php echo $cast; ?></textarea>
              </p>
		  <p>Plot                  
                  <textarea name="plot" cols="40" rows="3" id="plot" ><?php echo $plot; ?></textarea>
              </p>
		  <p>Other Info        
                  <textarea name="otherinfo" cols="40" rows="5" id="otherinfo"><?php echo $otherinfo; ?></textarea>
		  Download links </p>
		  <p>
	         
	          <textarea name="download" cols="40" rows="5" id="textarea" ><?php echo $links; ?></textarea>
	      </p>
		  <p>
                <input type="submit" name="edit" value="Edit it" />
                <input type="reset" name="Submit2" value="Reset" />
              </p>
              

	  </form>
		<h3> </h3>

  </div>

<!-- wrap ends here -->
</div>

<!-- footer starts here -->
</body>
</html>

 

I did as you said but doesn't seem to work.When i try the echo the result the $id still isn't passin  :-[

Link to comment
Share on other sites

 

 

 

$result=mysql_query($sql) or die(mysql_error());  // extra ), possibly causing this to be an undefined function

// Should be

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

 

Also it appears that the session start headers were already sent in ob_start. As long as PHP is buffering the ouytput, the client can not get in. Call session_start before ob_start

Link to comment
Share on other sites

You're right the ) does need to be there to balance your code. I use a code based designer phpDesigner 2007 and it has a great debugger. I can't see what's in the includes, but if you try this software, it may be able to reveal any potential problems.

 

Also, have you reveresd the session_start  and ob_start

Link to comment
Share on other sites

I am a newbie at all of this, but when i have a problem with inserting into a database i go back to the start, with a simple insert query. Try that and see if it works

 

edit

 

are you sure your connecting to the database. I assume you connect with one of the include php files. Make sure you put in the variable name that referes to the database connection. Like $con. I maybe wrong as i am new to this

Link to comment
Share on other sites

Again, where is $id coming from? Via a URL, or a form in another script? If it's a form, are you sure ID isn't being sent as a POST instead of a GET? Is it being sent at all? (usually, such things are sent in hidden form fields).

 

Anyways, you have posted your 'complete code', but your code asks for $id from a GET. If you want $id to be there, you have to ensure it's being sent.

 

PhREEEk

Link to comment
Share on other sites

  • 2 weeks later...
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.