livewirerules Posted October 11, 2007 Share Posted October 11, 2007 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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/ Share on other sites More sharing options...
otuatail Posted October 11, 2007 Share Posted October 11, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-367002 Share on other sites More sharing options...
richardw Posted October 11, 2007 Share Posted October 11, 2007 How or Where are you defining the $id used to update the record? WHERE id='$id'"; Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-367062 Share on other sites More sharing options...
livewirerules Posted October 11, 2007 Author Share Posted October 11, 2007 $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 Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-367105 Share on other sites More sharing options...
richardw Posted October 11, 2007 Share Posted October 11, 2007 I use the . in my select query. WHERE id = ". $_GET["id"]; or try for test purposes redefine the id variable by adding it on the line before the $sql="UPDATE ..." $id = ". $_GET["id"]; best Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-367115 Share on other sites More sharing options...
livewirerules Posted October 12, 2007 Author Share Posted October 12, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-367707 Share on other sites More sharing options...
livewirerules Posted October 15, 2007 Author Share Posted October 15, 2007 any help on this pls Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-369770 Share on other sites More sharing options...
padams Posted October 15, 2007 Share Posted October 15, 2007 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']); Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-369784 Share on other sites More sharing options...
livewirerules Posted October 15, 2007 Author Share Posted October 15, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-369825 Share on other sites More sharing options...
richardw Posted October 15, 2007 Share Posted October 15, 2007 $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 Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-369881 Share on other sites More sharing options...
livewirerules Posted October 15, 2007 Author Share Posted October 15, 2007 i tried it but doesnt work.But when i remove the ) i get an error.I think the way i have put is right.Coz in the die() i have used the mysql_error().So the mysql error will be displayed..Pls some one help me oon Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-369899 Share on other sites More sharing options...
richardw Posted October 15, 2007 Share Posted October 15, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-369917 Share on other sites More sharing options...
livewirerules Posted October 17, 2007 Author Share Posted October 17, 2007 i tried it but still doesnt work...pls some one help me..i cant complete my system because of this error issue ??? Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-371495 Share on other sites More sharing options...
adam291086 Posted October 17, 2007 Share Posted October 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-371497 Share on other sites More sharing options...
livewirerules Posted October 18, 2007 Author Share Posted October 18, 2007 the database connectivity is fine coz in the code there are 2 sql executions the first one works fine but the second one doesnt work coz it doesnt pass the id Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-372126 Share on other sites More sharing options...
PHP_PhREEEk Posted October 18, 2007 Share Posted October 18, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-372179 Share on other sites More sharing options...
livewirerules Posted October 20, 2007 Author Share Posted October 20, 2007 I'm getting the id from a URL. First i assigned $id=$_get[id]. the id is passed in the first sql execution but not in the second one which updates the database. next i directly user $_get[id] in the WHERE id= clause.it does the same the fist one passes the id but not the second one. Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-373861 Share on other sites More sharing options...
PHP_PhREEEk Posted October 21, 2007 Share Posted October 21, 2007 Sorry I have been away for a couple of days... If this is still an issue, can you please post the URL you are sending to this script that has the ID number in it? PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-375025 Share on other sites More sharing options...
livewirerules Posted November 2, 2007 Author Share Posted November 2, 2007 http://localhost/final/editmovieinfo.php?id=2 when i try to edit the id isn't passing. Quote Link to comment https://forums.phpfreaks.com/topic/72772-update-problem/#findComment-383364 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.