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

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 2.31 KB  |  hits: 7  |  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. Split column via query to insert extract into another column. Not working
  2. <?
  3.  $host     = "XXXXXXX";
  4.  $username = "XXXXXXX";
  5.  $password = "XXXXXXX";
  6.  $db_name  = "XXXXXXX";
  7.  $tbl_name = "cartons_current";
  8.  
  9.  mysql_connect("$host", "$username", "$password") or die("cannot connect");
  10.  mysql_select_db("$db_name") or die("cannot select DB");
  11.  
  12.  date_default_timezone_set('America/Los_Angeles');
  13.  $date = date("m/d/y g:i A");
  14.  $order = "INSERT INTO cartons_current (orig_time, type, part_no, description, artwork, min, max, qty)
  15.         VALUES
  16.         ('$date','$_POST[type]', '$_POST[part_no]', '$_POST[description]',       '$_POST[artwork]', '$_POST[min]', '$_POST[max]', '$_POST[qty]')";
  17.  
  18.  
  19.  
  20.  
  21.  $result = mysql_query($order);
  22.  
  23.  $query2 = "select part_no from cartons_current";
  24.  $sel = mysql_query($query2);
  25.  while($row = mysql_fetch_row($sel)) {
  26.  $core_digits = explode('-',$row[0]);
  27.  $core =$core_digits[1];
  28.  $query3 = "insert  into cartons_current(core) values('$core')";
  29.  $sel2 = mysql_query($query3);
  30.  }
  31.  
  32.  
  33.  
  34.  if ($result) {
  35.  
  36.  
  37.  $part_no = $_REQUEST['part_no'] ;
  38.  
  39.  header("location: inv_fc_new_success.php?part_no=" . urlencode($part_no));
  40.  }
  41.  else {
  42.   header("location: inv_fc_new_fail.php");
  43.  }
  44.  ?>
  45.        
  46. UPDATE cartons_current
  47. SET core = SUBSTR(part_no, 5, 5)
  48.        
  49. $core = substr($_POST['part_no'], 5, 5);
  50. $type = mysql_real_escape_string($_POST['type']);
  51. $part_no = mysql_real_escape_string($_POST['part_no']);
  52. $description = mysql_real_escape_string($_POST['description']);
  53. $artwork = mysql_real_escape_string($_POST['artwork']);
  54. $min = mysql_real_escape_string($_POST['min']);
  55. $max = mysql_real_escape_string($_POST['max']);
  56. $qty = mysql_real_escape_string($_POST['qty']);
  57. $order = "
  58.     INSERT INTO cartons_current
  59.     (
  60.         orig_time,
  61.         type,
  62.         part_no,
  63.         description,
  64.         artwork,
  65.         min,
  66.         max,
  67.         qty,
  68.         core
  69.     )
  70.     VALUES
  71.     (
  72.         '$date',
  73.         '$type',
  74.         '$part_no',
  75.         '$description',
  76.         '$artwork',
  77.         $min,
  78.         $max,
  79.         $qty,
  80.         '$core'
  81.     )";
  82.  
  83. $result = mysql_query($order);
  84.        
  85. $query2 = "select part_no from cartons_current";
  86. $sel = mysql_query($query2);
  87. while($row = mysql_fetch_row($sel)) {
  88.  $core_digits = explode('-',$row[0]);
  89.  $core =$core_digits[1];
  90.  $query3 = "insert  into cartons_current(core) values('$core')";
  91.  $sel2 = mysql_query($query3);
  92. }