Jump to content

Help a newbie out - Understanding some code


snteran

Recommended Posts

I have inherited some php code that I am trying to update.  The issue is that I am very new to programming and php, I have had some experience with html and seen php but never really worked with it.  I am hoping to become stronger at php but need some help getting started.  I was hoping to post some code and hopefully get some explanation as to what is going on.

 

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "edit_notes")) {
  $updateSQL = sprintf("UPDATE itc_tickets SET lastupdt_date=NOW(), lastupdt_usr=%s WHERE ticket_nbr=%s", <----- code ?
				   GetSQLValueString($_POST['current_usr'], "text"),
				   GetSQLValueString($_POST['ticket_nbr'], "int"));

  mysql_select_db($database_itc_admin, $itc_admin);
  $Result1 = mysql_query($updateSQL, $itc_admin) or die(mysql_error());
}

 

another example:

 

mysql_select_db($database_itc_admin, $itc_admin);
$query_ticket_notes = sprintf("SELECT recordid, ticket_nbr, notes_body, create_date, create_user FROM itc_tickets_notes WHERE recordid = %s <----code ? ORDER BY create_date DESC", $colname_ticket_notes);
$ticket_notes = mysql_query($query_ticket_notes, $itc_admin) or die(mysql_error());
$row_ticket_notes = mysql_fetch_assoc($ticket_notes);
$totalRows_ticket_notes = mysql_num_rows($ticket_notes);

 

What I am trying to do is edit an existing note that was added to a ticket.  I was able to make available for admin users the ability to edit notes, I have a link that goes to an edit_note.php page.  I basically am using an existing page that was used to add notes and I am trying to edit it to work for my purposes. (Hack 101)  In the above code, I don't understand the "ticket_nbr=%s"  entry.  I see how they use the "%s" throughout the code but I don't understand how a value is assigned to that part of the equation.  I would be happy to add entire code, but not sure if that would be over kill.

 

thanks,

 

Sergio

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.