joshgarrod Posted June 9, 2009 Share Posted June 9, 2009 Hi, I just need a second pair of eyes to go over this script for me, It pulls the correct information for the record I want to edit. It just doesn't update, it says it has but it hasn't. I have this code working on another page but I have manipulated it for this but it doesn't work for some reason... any ideas? Thanks <?php error_reporting (E_ALL ^ E_NOTICE); $idir = "uploads/"; // Path To Images Directory $usr = "user"; $pwd = "pass"; $db = "quest"; $host = "host"; /***********************Upload File***********************/ if (isset ($_FILES['fupload'])) { //upload the image to tmp directory $url = $_FILES['fupload']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['fupload']['type'] == "image/jpg" || $_FILES['fupload']['type'] == "image/jpeg" || $_FILES['fupload']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['fupload']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['fupload']['tmp_name'], "$idir" . $_FILES['fupload']['name']); // Move Image From Temporary Location To Permanent Location } } /***********************Get Record***********************/ $ref = (!empty($_GET['ref']))?trim($_GET['ref']):""; # connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid){ echo("ERROR: " . mysql_error() . "\n"); } $db_selected = mysql_select_db('quest', $cid); $query = sprintf("SELECT * FROM shows where ref like '%s' LIMIT 1","%".mysql_real_escape_string($ref)."%"); $result = mysql_query($query) or die($query."<br>".mysql_error()); $record = mysql_fetch_assoc($result); if(mysql_num_rows($result) > 0) { echo "FOUND"; $ref=$record["ref"]; $title=$record["title"]; $descr=$record["descr"]; $location=$record["location"]; $startdate=$record["startdate"]; $enddate=$record["enddate"]; }else{ echo "NOT FOUND"; $ref=0; $title=""; $descr=""; $location=""; $startdate=""; $enddate=""; } /***********************Save Record***********************/ # this is processed when the form is submitted # back on to this page (POST METHOD) if (isset($_POST['submit'])){ $ref=$_POST["ref"]; $title=$_POST["title"]; $descr=$_POST["descr"]; $location=$_POST["location"]; $startdate=$_POST["startdate"]; $enddate=$_POST["enddate"]; # setup SQL statement $query = sprintf("UPDATE `shows` SET `title` = '%s',`descr` = '%s',`location` = '%s',`startdate` = '%s',`enddate` = '%s' WHERE `shows`.`ref` ='%s' LIMIT 1", mysql_real_escape_string($title),mysql_real_escape_string($descr),mysql_real_escape_string($location),mysql_real_escape_string($startdate),mysql_real_escape_string($enddate),mysql_real_escape_string($ref)); #execute SQL statement $result = mysql_db_query($db,$query,$cid) or die($query."<br>".mysql_error()); # check for error if (!$result){ echo("ERROR: " . mysql_error() . "\n$SQL\n"); } echo "<P>Part updated</P>\n"; } ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 9, 2009 Share Posted June 9, 2009 Echo the update query to the page. Chances are the values aren't getting set correctly. My guess is that if you are getting the message "Part updated" and no errors are displayed then the $ref value isn't getting set. Since you didn't provide the form, I can't tell whether there is even such a field on the form. Try adding the following lines after the confirmation message to validate teh post values and the query. Is it what you expect? echo "Query: <br />{$query}\n"; echo "Post Values: <br /><pre>"; print_r($_POST); echo "</pre>"; Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 9, 2009 Share Posted June 9, 2009 Edit: Some duplicate of the above ^^^^ post... First of all, only use E_ALL in the following (hiding Notice messages, the ^ E_NOTICE part, is probably hiding errors that would help pin point why your code is not working) - error_reporting (E_ALL ^ E_NOTICE); Echo out $query so that you know what it contains. Since it appears that the query is being executed, that would mean that your WHERE clause does not match any rows in your table or your table has more than one row and the LIMIT 1 is causing only one to be updated while you are examining a different one. Quote Link to comment Share on other sites More sharing options...
joshgarrod Posted June 9, 2009 Author Share Posted June 9, 2009 Thanks, thats what it was. I hand't set $ref wih the hidden field, thanks for the help Quote Link to comment 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.