Jump to content

Want to tweak the Update Record function to add instead of replace. DWMX


Recommended Posts

I have a reccomendation system instead of a rating system, and I'm using PHP and mySQL. The tutorial I found requires commands, and mySQL doesn't support that, so I thought that I could use a form and the update function that dreamweaver offers to add to the reccomendation count row.

Each time you press submit, it's supposed to add the value ("1") from a hidden field into the rec count row.

All I need to make it do is add one instead of replace what is already in the row. I'm not sure how to do this, as I am quite a newbie when it comes to coding in PHP. I don't want to screw anything up. Here is the code Dreamweaver spewed for my update record function, if you can help me modify it, I'd be much obliged:

[code]
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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "recupdate")) {
  $updateSQL = sprintf("UPDATE Fanfiction SET `Rec Count`=%s WHERE ID=%s",
                      GetSQLValueString($HTTP_POST_VARS['newreccount'], "int"),
                      GetSQLValueString($HTTP_POST_VARS['ID'], "int"));

  mysql_select_db($database_altpanfics, $altpanfics);
  $Result1 = mysql_query($updateSQL, $altpanfics) or die(mysql_error());

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

$colname_showFic = "1";
if (isset($HTTP_GET_VARS['ficShowID'])) {
  $colname_showFic = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['ficShowID'] : addslashes($HTTP_GET_VARS['ficShowID']);
}
mysql_select_db($database_altpanfics, $altpanfics);
$query_showFic = sprintf("SELECT * FROM Fanfiction WHERE ID = %s", $colname_showFic);
$showFic = mysql_query($query_showFic, $altpanfics) or die(mysql_error());
$row_showFic = mysql_fetch_assoc($showFic);
$totalRows_showFic = mysql_num_rows($showFic);
[/code]
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.