Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 1.80 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Passing the ID from one page to another [closed]
  2. echo "<td> <a href='products.php?IsEdit=1&ProductID=" .$row['ProductID']. "'> Edit </a></td>";
  3.        
  4. <?php
  5.  
  6. global $ID;
  7. $ID = $_GET['ProductID'];
  8.        
  9. <?php
  10.  if(isset($_GET['IsEdit']))  
  11.  { ?>
  12.  <input type="submit" name = "update" value="UPDATE" onClick="return valid();"  />
  13.  <?php }else { ?>          
  14.  <input type="submit" name = "submit" value="ADD PRODUCT" onClick="return valid();"  />
  15.  <?php } ?>
  16.  
  17. if (isset($_POST['update']))
  18.  {
  19.  
  20.  
  21.  $ProductName = mysql_real_escape_string(htmlspecialchars($_POST['ProductName']));
  22.     $ProductCode = $_POST['ProductCode'];
  23.     $Manufacturer = $_POST['Manufacturer'];
  24.     $Specification = $_POST['Specification'];
  25.     $Description = $_POST['Description'];
  26.     $CostPrice = $_POST['CostPrice'];
  27.     $DisplayPrice = $_POST['DisplayPrice'];
  28.  
  29.     echo "Pr ID";
  30.     echo $ID;
  31.     $ProductImage = $_POST['ProductImage'];
  32.  //{
  33.  echo "2";
  34.  if ($ProductName == '' || $ProductCode == ''|| $Manufacturer == '' || $Description == '' || $Specification == '' || $CostPrice == '' || $DisplayPrice == '')
  35.  {
  36.  // generate error message
  37.  $error = 'ERROR: Please fill in all required fields!';
  38.  echo "3";
  39.  //error, display form
  40.  //renderForm('', $ProductID, $ProductName, $ProductCode, $Manufacturer, $Description, $Specification,'', $CostPrice, $DisplayPrice, $error);
  41.  }
  42.  else
  43.  {
  44.  // save the data to the database
  45.  $sql = "UPDATE Products SET ProductName='$ProductName', ProductCode='$ProductCode', Manufacturer='$Manufacturer', Description='$Description', Specification='$Specification', CostPrice='$CostPrice', DisplayPrice='$DisplayPrice' WHERE ProductID=" . $_SESSION['ID'];
  46.  echo $sql;
  47.  mysql_query($sql) or die(mysql_error());
  48.  
  49.  // once saved, redirect back to the view page
  50.  //header("Location: view.php");
  51.  }
  52.  
  53.  //}
  54.  }
  55.        
  56. $row['ProductID'] have valid data