Jump to content

Any Comments?


kreut

Recommended Posts

Hello!

 

I'm trying to dive into Dreamweaver's code so that I can better understand what the heck it's doing in order to modify it to my specific needs.  My PHP book is great, but it just seems like Dreamweaver's code is much more complicated than how I'd write it based on what I've read about PHP (Disclaimer: been with PHP for a week).  It would be incredibly helpful if someone could write comments for each of the lines in terms of what it's doing (the more specific the better).  I appreciate that this is a bit of a tedious question to ask, but it would be really appreciated.

 

Thank you.

 

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

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO users (first_name, last_name, user_type, email, school_id) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['first_name'], "text"),
                       GetSQLValueString($_POST['last_name'], "text"),
                       GetSQLValueString($_POST['user_type'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['school_id'], "int"));
				   
  mysql_select_db($database_connalgebra, $connalgebra);
  $Result1 = mysql_query($insertSQL, $connalgebra) or die(mysql_error());
  		   

// The code below gives the last autogenerated userid.
$id = mysql_insert_id();
$updateusername = "UPDATE users SET username = CONCAT(first_name, $id) WHERE user_id = $id";
$Result2 = mysql_query($updateusername, $connalgebra) or die(mysql_error());
//

  $insertGoTo = "add_user.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_connalgebra, $connalgebra);
$query_rsSchools = "SELECT school_id, school_state, school_city, school_name, school_country FROM schools ORDER BY school_name ASC";
$rsSchools = mysql_query($query_rsSchools, $connalgebra) or die(mysql_error());
$row_rsSchools = mysql_fetch_assoc($rsSchools);
$totalRows_rsSchools = mysql_num_rows($rsSchools);

Link to comment
Share on other sites

Sorry about that!  Is this better?

 

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

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO users (first_name, last_name, user_type, email, school_id) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['first_name'], "text"),
                       GetSQLValueString($_POST['last_name'], "text"),
                       GetSQLValueString($_POST['user_type'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['school_id'], "int"));
				   
  mysql_select_db($database_connalgebra, $connalgebra);
  $Result1 = mysql_query($insertSQL, $connalgebra) or die(mysql_error());
  		   

// The code below gives the last autogenerated userid.
$id = mysql_insert_id();
$updateusername = "UPDATE users SET username = CONCAT(first_name, $id) WHERE user_id = $id";
$Result2 = mysql_query($updateusername, $connalgebra) or die(mysql_error());
//

  $insertGoTo = "add_user.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_connalgebra, $connalgebra);
$query_rsSchools = "SELECT school_id, school_state, school_city, school_name, school_country FROM schools ORDER BY school_name ASC";
$rsSchools = mysql_query($query_rsSchools, $connalgebra) or die(mysql_error());
$row_rsSchools = mysql_fetch_assoc($rsSchools);
$totalRows_rsSchools = mysql_num_rows($rsSchools);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.