Read a Record

Note that any time you get strings back from a database you have to worry about stripping the escape characters from it. Please read the relevant posts on this subject if your not sure you are doing the right thing regarding this.

function reloadDataVars() {
/* Puts the data from an existent part record into the
variables which will populate an update form. It is assumed
that $label and $partNumber correspond to a part record which
exists already. Also, this function makes sure that all form
variables get initialized with values and defined as global.
Otherwise, it aborts.

  // All form variables are global.
  global $label, $manufacturer, $retailer, $partNumber, $price, $quantityHave;

  $query = "SELECT manufacturer, retailer, price, quantityHave
            FROM maintenVehicleParts
            WHERE label = '$label' AND partNumber = '$partNumber'";
  $result = mysql_query($query);
  if (!$result || mysql_num_rows($result) < 1) {
    die('Error 56801. -Programmer.');
  } else {
    $user_array = mysql_fetch_array($result);
    $manufacturer = $user_array['manufacturer'];
    $retailer = $user_array['retailer'];
    $price = $user_array['price'];
    $quantityHave = $user_array['quantityHave'];
    // Text and Textarea fields have had backslashes
    // added to escape single quotes ('), double
    // quotes ("), backslashes (\) and NULL before
    // insertion into the database. Therefore, we must
    // undo this before displaying these strings.
    $manufacturer = stripslashes($manufacturer);
    $retailer = stripslashes($retailer);
    // Even though $label and $partNumber were
    // not retrieved
    $label = stripslashes($label);
    $partNumber = stripslashes($partNumber);


  $query = "SELECT scriptFileName, scriptFileDir, shortTitle
            FROM kds_kda
            WHERE id='$kdaId'";
  $result = mysql_query($query);
  if (!$result) {
    die('Query failed. Err: 1215895096. -Programmer.');
  if (mysql_num_rows($result) != 1) {
    die('Query failed. Err: 7805485985. -Programmer.');
  $row = mysql_fetch_array($result, MYSQL_ASSOC);
  $scriptFileName = $row['scriptFileName'];
  $scriptFileDir = $row['scriptFileDir'];
  $shortTitle = $row['shortTitle'];
  $shortTitle = stripslashes($shortTitle);

About samehramzylabib

See About on
This entry was posted in Coding, Database and tagged , , . Bookmark the permalink.