title: php - update set & delete issues - save deleting records
body: <p>I have a script for editing existing data. A fetch array is used to populate fields with data and queries for deleting the record and amending the record. When I click Save the record is deleted and not saved even though it has the correct id.</p>
  
  <pre><code>$feedid = mysql_real_escape_string($_POST['feedid']);
  
  $Query = "UPDATE ccregisterfeed SET author='$author', category='$category',
  copyright='$copyright', feeddescription='$feeddescription', feedtitle='$feedtitle',
  websitelink='$websitelink', imagelink='$imagelink', imagetitle='$imagetitle',
  subtitle='$subtitle' WHERE id='$feedid' AND username ='$user'";
  </code></pre>
  
  <p>And the input paired with the id :</p>
  
  <pre><code>&lt;div class="submit"&gt;&lt;input name="Submit" type="submit" class="submitbtn" value="Save"/&gt;&lt;/div&gt;
  &lt;input type="hidden" name="feedid" value="&lt;?php echo $id; ?&gt;"/&gt;
  </code></pre>
  
  <p>If I remove the delete input clicking save works.</p>
  
  <pre><code>&lt;div class="delete"&gt;&lt;input name="Delete" type="submit" class="deletebtn" value="Delete"/&gt;&lt;/div&gt;
  &lt;input type="hidden" name="Delete" value="&lt;?php echo $id; ?&gt;"&gt;
  </code></pre>
  
  <p>FULL SCRIPT</p>
  
  <pre><code>&lt;?php
  include "connect.php";
  require "authenticate.php";
  error_reporting(E_ERROR);
  $message = $_GET['message'];
  $user = $_SESSION['UserName'];
  
  //declare form field and form field error variables
  $authorErr = $categoryErr = $copyrightErr = $feeddescriptionErr = $feedlinkErr = $feedtitleErr = $websitelinkErr = $imagelinkErr = $imagetitleErr = $subtitleErr = "";
  $author = $category = $copyright = $feeddescription = $feedlink = $feedtitle = $websitelink = $imagelink = $imagetitle = $subtitle = "";
  
  //form field validation
  function validate_input($data)
  {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
  }
  
  if (isset($_POST['Submit']))
  {
  if (empty($_POST["author"])) {
  $has_errors = true;
  $authorErr = "Enter your name";
  }else{
  $author = validate_input($_POST["author"]);
  }
  
  if (empty($_POST["category"])) {
  $has_errors = true;
  $categoryErr = "Enter a category";
  }else {
  $category = validate_input($_POST["category"]);
  }
  
  if (empty($_POST["copyright"])) {
  $has_errors = true;
  $copyrightErr = "Enter copyright details";
  } else {
  $copyright = validate_input($_POST["copyright"]);
  }
  
  if (empty($_POST["feeddescription"])) {
  $has_errors = true;
  $feeddescriptionErr = "Enter feed description";
  } else {
  $feeddescription = validate_input($_POST["feeddescription"]);
  }
  
  if (empty($_POST["feedtitle"])) {
  $has_errors = true;
  $feedtitleErr = "Enter text only";
  } else {
  $feedtitle = validate_input($_POST["feedtitle"]);
  }
  
  if (empty($_POST["websitelink"])) {
  $has_errors = true;
  $websitelinkErr = "Enter link to website";
  } else {
  $websitelink = validate_input($_POST["websitelink"]);
  }
  
  if (empty($_POST["imagelink"])) {
  $has_errors = true;
  $imagelinkErr = "Enter link to image";
  } else {
  $imagelink = validate_input($_POST["imagelink"]);
  }
  
  if (empty($_POST["imagetitle"])) {
  $has_errors = true;
  $imagetitleErr = "Enter image name";
  } else {
  $imagetitle = validate_input($_POST["imagetitle"]);
  }
  
  if (empty($_POST["subtitle"])) {
  $has_errors = true;
  $subtitleErr = "Enter feed subtitle";
  } else {
  $subtitle = validate_input($_POST["subtitle"]);
  }
  
  if (!$has_errors)
  {
      $Link = mysql_connect($Host, $User, $Password);
      $user = $_SESSION['UserName'];
      }
  
  // var_dump ($date);
  // var_dump ($feedlink);
  // var_dump ($feeddescription);
  
  //write edited data into tables matching logged in user with their data
  $feedid = mysql_real_escape_string($_POST['feedid']);
  
  $date = date("Y-m-d H:i:s");
  
  $feeddescription = str_replace("_", "", $feeddescription);
  $feeddescription = str_replace("-", "", $feeddescription);
  $feeddescription = str_replace("!", "", $feeddescription);
  $feeddescription = str_replace("#", "", $feeddescription);
  $feeddescription = str_replace("'", "", $feeddescription);
  
  $Query = "UPDATE ccregisterfeed SET author='$author', category='$category', copyright='$copyright', feeddescription='$feeddescription', feedtitle='$feedtitle', websitelink='$websitelink', imagelink='$imagelink', imagetitle='$imagetitle', subtitle='$subtitle' WHERE id='$feedid' AND username ='$user'";
  
  if($sql = mysql_db_query ($DBName, $Query, $Link)) {
  header("location: rss.php");
  // header("location: feededit.php");
  } else {
  die("Query was: $Query. Error: ".mysql_error($Link));
  }
  }
  
  //show logged in user their updated data
  $user = $_SESSION['UserName'];
  $result = mysql_query("SELECT * FROM ccregisterfeed WHERE username = '$user'") or die(mysql_error());
  while($row = mysql_fetch_array($result)){
  $id=$row['id'];
  $author = $row['author'];
  $category = $row['category'];
  $copyright = $row['copyright'];
  $feeddescription = $row['feeddescription'];
  $feedtitle = $row['feedtitle'];
  $websitelink = $row['websitelink'];
  $imagelink = $row['imagelink'];
  $imagetitle = $row['imagetitle'];
  $subtitle = $row['subtitle'];
  }
  
  //delete form and image data when users clicks delete button
  if (isset($_POST['Delete'])){
  $deleteuser = $_POST['Delete'];
  mysql_query("DELETE FROM ccregisterfeed WHERE id = '$deleteuser'");
  mysql_query("ALTER TABLE ccregisterfeed AUTO_INCREMENT = 1");
  $message = 'Feed Deleted';
  header("Location: feededit.php?&amp;message=".urlencode($message));
  }
  ?&gt;
  
  &lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  
  &lt;script&gt;
  $(function(){
  $(document).click(function(){  
  $('.messagebox').hide();
  });
  });
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;form action="feededit.php" method="post" enctype="multipart/form-data" name="edit" id="editfeed"&gt;
  
  &lt;fieldset&gt;
  &lt;div class="legendcreate"&gt;Feed Edit&lt;/div&gt;
  
  &lt;div class="feedcontainer"&gt;
  &lt;div class="feedcontainerinner"&gt;
  
  &lt;div&gt;&lt;label class="labelshow"&gt;Author&lt;/label&gt;&lt;input id="author" class="insetfeed" name="author" type="text" placeholder="Author" value="&lt;?PHP print $author ; ?&gt;"/&gt;&lt;p class="errorinput"&gt;&lt;?php echo $authorErr;?&gt;&lt;/p&gt;&lt;/div&gt;
  
  &lt;?php if(isset($_GET['message']) &amp;&amp; !empty($message)): ?&gt;
  &lt;div class="messagebox"&gt;
  &lt;?php echo $message ?&gt;
  &lt;/div&gt;
  &lt;?php endif; ?&gt;
  
  &lt;div&gt;&lt;label class="labelshow"&gt;Category&lt;/label&gt;&lt;input id="category" class="insetfeed" name="category" type="text" placeholder="Category" value="&lt;?PHP print $category; ?&gt;"/&gt;&lt;p class="errorinput"&gt;&lt;?php echo $categoryErr;?&gt;&lt;/p&gt;&lt;/div&gt;
  
  &lt;div&gt;&lt;label class="labelshow"&gt;Copyright&lt;/label&gt;&lt;input id="copyright" class="insetfeed" name="copyright" type="text" placeholder="Copyright" value="&lt;?PHP print $copyright; ?&gt;"/&gt;&lt;p class="errorinput"&gt;&lt;?php echo $copyrightErr;?&gt;&lt;/p&gt;&lt;/div&gt;
  
  &lt;div&gt;&lt;label class="labelshow"&gt;Feed Title&lt;/label&gt;&lt;input id="feedtitle" class="insetfeed" name="feedtitle" type="text" placeholder="Feed Title" value="&lt;?PHP print $feedtitle; ?&gt;"/&gt;&lt;p class="errorinput"&gt;&lt;?php echo $feedtitleErr;?&gt;&lt;/p&gt;&lt;/div&gt;
  
  &lt;div&gt;&lt;label class="labelshow"&gt;Website Link&lt;/label&gt;&lt;input id="websitelink" class="insetfeed" name="websitelink" type="text" placeholder="Website Link" value="&lt;?PHP print $websitelink; ?&gt;"/&gt;&lt;p class="errorinput"&gt;&lt;?php echo $websitelinkErr;?&gt;&lt;/p&gt;&lt;/div&gt;
  
  &lt;div&gt;&lt;label class="labelshow"&gt;Image Link&lt;/label&gt;&lt;input id="imagelink" class="insetfeed" name="imagelink" type="text" placeholder="Image Link" value="&lt;?PHP print $imagelink; ?&gt;"/&gt;&lt;p class="errorinput"&gt;&lt;?php echo $imagelinkErr;?&gt;&lt;/p&gt;&lt;/div&gt;
  
  &lt;div&gt;&lt;label class="labelshow"&gt;Image Title&lt;/label&gt;&lt;input id="imagetitle" class="insetfeed" name="imagetitle" type="text" placeholder="Image Title" value="&lt;?PHP print $imagetitle; ?&gt;"/&gt;&lt;p class="errorinput"&gt;&lt;?php echo $imagetitleErr;?&gt;&lt;/p&gt;&lt;/div&gt;
  
  &lt;div&gt;&lt;label class="labelshow"&gt;Subtitle&lt;/label&gt;&lt;input id="subtitle" class="insetfeed" name="subtitle" type="text" placeholder="Subtitle" value="&lt;?PHP print $subtitle; ?&gt;"/&gt;&lt;p class="errorinput"&gt;&lt;?php echo $subtitleErr;?&gt;&lt;/p&gt;&lt;/div&gt;
  
  &lt;div&gt;&lt;textarea id="description" name="feeddescription" class="textareadescription" placeholder="Enter feed description"&gt;&lt;?php
      $out = htmlspecialchars_decode($feeddescription); 
      $out = str_replace( '\n', '&lt;br /&gt;', $out ); 
      echo $out; 
      ?&gt;&lt;/textarea&gt;
  
  &lt;div class="submit"&gt;&lt;input name="Submit" type="submit" class="submitbtn" value="Save"/&gt;&lt;/div&gt;
  &lt;input type="hidden" name="feedid" value="&lt;?php echo $id; ?&gt;"/&gt;
  
  &lt;div class="delete"&gt;&lt;input name="Delete" type="submit" class="deletebtn" value="Delete"/&gt;&lt;/div&gt;
  &lt;input type="hidden" name="Delete" value="&lt;?php echo $id; ?&gt;"&gt;
  
  
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;/form&gt;
  &lt;/fieldset&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>