Jump to content

Recommended Posts

hey all, im having trouble with my reply form in the case its not inserting data into my table; It calls all the data from my message perfectly and this is what I think my problem is; the fact it calls all my data from the msg id, then it should insert into a new row and autoinc my ID; im new to this so im sorry if this seems a bit confusing, thanks

 

heres my page

 

<?php require_once(''); ?>
<?php
// Load the common classes
require_once('includes/common/KT_common.php');

// Load the tNG classes
require_once('includes/tng/tNG.inc.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("");

// Make unified connection variable
$ = new KT_connection($connectiony stuff);

//Start Restrict Access To Page
$restrict = new tNG_RestrictAccess($connection, "");
//Grand Levels: Level
$restrict->addLevel("1");
$restrict->Execute();
//End Restrict Access To Page

// Start trigger
$formValidation = new tNG_FormValidation();
$formValidation->addField("sender", true, "text", "", "1", "70", "");
$formValidation->addField("subject", true, "text", "", "1", "70", "Please enter a subject");
$formValidation->addField("message", true, "text", "", "1", "255", "You forgot to enter a message");
$tNGs->prepareValidation($formValidation);
// End trigger

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

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}

$colname_reply_msg_id = "-1";
if (isset($_GET['msg_id'])) {
  $colname_reply_msg_id = $_GET['msg_id'];
}
mysql_select_db($database_db99, $db99);
$query_reply_msg_id = sprintf("SELECT * FROM messages_test WHERE id = %s", GetSQLValueString($colname_reply_msg_id, "int"));
$reply_msg_id = mysql_query($query_reply_msg_id, $db99) or die(mysql_error());
$row_reply_msg_id = mysql_fetch_assoc($reply_msg_id);
$totalRows_reply_msg_id = mysql_num_rows($reply_msg_id);

// Make a logout transaction instance
$logoutTransaction = new tNG_logoutTransaction($connection);
$tNGs->addTransaction($logoutTransaction);
// Register triggers
$logoutTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "GET", "KT_logout_now");
$logoutTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "index.php");
// Add columns
// End of logout transaction instance

// Make an insert transaction instance
$ins_messages_test = new tNG_insert($connection here);
$tNGs->addTransaction($ins_messages_test);
// Register triggers
$ins_messages_test->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_messages_test->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$ins_messages_test->registerTrigger("END", "Trigger_Default_Redirect", 99, "member_area.php?message=Message sent successfully!");
// Add columns
$ins_messages_test->setTable("messages_test");
$ins_messages_test->addColumn("datetime", "DATE_TYPE", "POST", "datetime");
$ins_messages_test->addColumn("replied", "STRING_TYPE", "POST", "replied", "1");
$ins_messages_test->addColumn("trash", "STRING_TYPE", "POST", "trash");
$ins_messages_test->addColumn("sender_has", "STRING_TYPE", "POST", "sender_has");
$ins_messages_test->addColumn("reciever_has", "STRING_TYPE", "POST", "reciever_has");
$ins_messages_test->addColumn("reciever", "STRING_TYPE", "POST", "reciever");
$ins_messages_test->addColumn("sender", "STRING_TYPE", "POST", "sender");
$ins_messages_test->addColumn("subject", "STRING_TYPE", "POST", "subject");
$ins_messages_test->addColumn("message", "STRING_TYPE", "POST", "message");
$ins_messages_test->addColumn("recieved", "STRING_TYPE", "POST", "recieved");
$ins_messages_test->setPrimaryKey("id", "NUMERIC_TYPE");

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rscustom = $tNGs->getRecordset("custom");
$row_rscustom = mysql_fetch_assoc($rscustom);
$totalRows_rscustom = mysql_num_rows($rscustom);

// Get the transaction recordset
$rsmessages_test = $tNGs->getRecordset("messages_test");
$row_rsmessages_test = mysql_fetch_assoc($rsmessages_test);
$totalRows_rsmessages_test = mysql_num_rows($rsmessages_test);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<style type="text/css">

body    {
margin:0;
}

</style>
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="includes/common/js/base.js" type="text/javascript"></script>
<script src="includes/common/js/utility.js" type="text/javascript"></script>
<script src="includes/skins/style.js" type="text/javascript"></script>
<link href="styles.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style4 {color: #F4F5F5}
.style5 {color: #3B5A9A}
-->
</style>
<?php echo $tNGs->displayValidationRules();?>
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="includes/common/js/base.js" type="text/javascript"></script>
<script src="includes/common/js/utility.js" type="text/javascript"></script>
<script src="includes/skins/style.js" type="text/javascript"></script>
<?php echo $tNGs->displayValidationRules();?>
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="includes/common/js/base.js" type="text/javascript"></script>
<script src="includes/common/js/utility.js" type="text/javascript"></script>
<script src="includes/skins/style.js" type="text/javascript"></script>
</head>

<BODY MARGINWIDTH="0" MARGINHEIGHT="0">
<?php include'member_header.php';?>
<table width="800" height="81" border="0" align="center" cellpadding="0" cellspacing="0" vspace="0">
  
  
  <tr>
    <td width="269" height="52" align="center" valign="middle"><div align="left">
      <p>
        <?php 
// Show IF Conditional region2 
if (@$_SESSION['kt_login_user'] == "") {
?>
        <a href="index.php"><img src="images/logo.gif" alt="" width="149" height="35" hspace="5" border="0" usemap="#MapMap" /></a>
        <?php 
// else Conditional region2
} else { ?>
        <a href="member_area.php"><img src="images/logo.gif" alt="" width="149" height="35" hspace="5" border="0" usemap="#MapMap" /></a>
        <?php } 
// endif Conditional region2
?>
      </p>
      <?php
echo $tNGs->getErrorMsg();
?>



</div></td>
  </tr>
  <tr>
    <td height="29" align="center" valign="middle"><?php include'navbar.php';?></td>
  </tr>
</table>
<br />
<table width="800" align="center" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td colspan="4" valign="middle" nowrap="nowrap" bgcolor="#F1F1F1" class="style2"><img src="images/corner2.gif" width="28" height="15" /><strong>My Account</strong></td>
  </tr>
  <tr>
    <td width="26" height="200" valign="top" bgcolor="#f1f1f1"><p><span class="style4"></span></p>    </td>
    <td width="154" height="200" valign="middle" bgcolor="#f1f1f1"><?php include'cp_links.php';?>  </td>
    <td width="13" height="200" valign="middle" nowrap="nowrap" class="cpcontenttop"> </td>
    <td width="607" rowspan="2" valign="top" class="cpcontent"><p class="profilehdr">Profile<br />
      Reply to Message 
      
      </p>
     
      <form action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>" method="post" name="form1" id="form1">
        <table cellpadding="2" cellspacing="0">
          <tr>
            <td width="89" valign="top" class="message_rows_subject">To</td>
            <td class="message_to"><?php echo KT_escapeAttribute($row_reply_msg_id['sender']); ?> </td>
          </tr>
          <tr>
            <td width="89" valign="top" class="message_rows_subject">Subject</td>
      <td><input type="text" name="subject" id="subject" value="RE: <?php echo KT_escapeAttribute($row_reply_msg_id['subject']); ?>" size="32" />
                <?php echo $tNGs->displayFieldHint("subject");?> <?php echo $tNGs->displayFieldError("messages_test", "subject"); ?> </td>
          </tr>
          <tr>
            <td width="89" valign="top" class="message_rows_subject">Message</td>
            <td valign="top"><textarea name="message" type="text" id="message" value="" cols="20" rows="20"style="width:470px;resize:none;">----------------- Original Message -----------------<?php print "\n";echo $row_reply_msg_id['message']; ?></textarea>
              <br />
              <?php echo $tNGs->displayFieldHint("message");?> <?php echo $tNGs->displayFieldError("messages_test", "message"); ?> </td>
          </tr>
          <tr class="KT_buttons">
            <td width="89"><div align="left">
              <input type="submit" name="KT_Insert1" id="KT_Insert1" value="Send" />            
            </div></td>
            <td align="left"> </td>
          </tr>
        </table>
        <input type="hidden" name="datetime" id="datetime" value="<?php echo KT_formatDate($row_rsmessages_test['datetime']); ?>" />
        <input type="hidden" name="trash" id="trash" value="<?php echo KT_escapeAttribute($row_rsmessages_test['trash']); ?>" />
        <input type="hidden" name="sender_has" id="sender_has" value="<?php echo KT_escapeAttribute($row_rsmessages_test['sender_has']); ?>" />
        <input type="hidden" name="reciever_has" id="reciever_has" value="<?php echo KT_escapeAttribute($row_rsmessages_test['reciever_has']); ?>" />
        <input type="hidden" name="replied" id="replied" value="<?php echo KT_escapeAttribute($row_reply_msg_id['replied']); ?>" />
      </form>
      <p> </p>
      </p>
<p></p>
      <p class="text1">
      <p>
        <label></label>
</p>
      <br />
      </p>
      </p></td>
  </tr>
  
  <tr>
    <td colspan="2" valign="top" nowrap="nowrap" bgcolor="#Ffffff" class="style2"> </td>
    <td width="13" valign="middle" nowrap="nowrap" class="cpcontentleft"> </td>
  </tr>
</table>
<br />
<br />


</body>
</html>
<?php
mysql_free_result($reply_msg_id);
?>

Link to comment
https://forums.phpfreaks.com/topic/107849-solved-form-submission/
Share on other sites

// Make unified connection variable

$ = new KT_connection($connectiony stuff);

 

did you forget to actually add the connectiony stuff??

 

 

something like

 

(This can be in a sep file if you want) unless you already have this somewhere int he variables that i have never seen)

$host =  " ";

$username = " ";

$password = " ";

$database = " ";

 

 

$con = mysql_connect("$host", "$user", "$passwd", "$database") or die("Could not

 

connect:".mysql_error());

 

I was just gonna ask that, prcollin!

 

I think you're missing some parameters.  You have "new KT_connection($connectiony stuff);" but "stuff" is just a string.  And I don't think $connectiony is actually an object.  Maybe $connection is.

 

I do not know how those functions work though, so I don't know what needs to be in there.  Do you have documentation?  Refer to that to see what parameters to pass.

that "connectiony stuff" is jsut my connection to database details thats all okay i just changed that for posting lol, and im new to php so im not to sure what you mean by parameters?

 

and for my connection at the top i have a require "variable?"

 

<?php require_once('Connections/db99.php'); ?>

 

i just dont know where im going wrong on the insert function, i have a recordset query which when i test works fine

If in your real code the $connection (or whatever) variable you pass to those functions/objects is your actual database connection, then it comes down to the two lines you posted before:

 

$ins_messages_test = new tNG_insert($connection here);
$tNGs->addTransaction($ins_messages_test);

 

Let's look at those logically: $ins_messages_test is a new tNG_insert object, that contains the DB connection.  It's then passed to addTransaction.  Here'd by my next two steps of troubleshooting: is $ins_messages_test supposed to contain the data to insert?  If so, then it looks like it doesn't.  Otherwise, addTransaction is supposed to already know that data -- so where's it get the data from.  What's inside the addTransaction function?

New thought (again, no idea how these classes actually work):

 

Try putting the addTransaction AFTER the registerTrigger statements:

 

/ Make an insert transaction instance
$ins_messages_test = new tNG_insert($connection here);

// Register triggers
$ins_messages_test->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_messages_test->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$ins_messages_test->registerTrigger("END", "Trigger_Default_Redirect", 99, "member_area.php?message=Message sent successfully!");
// Add columns
$ins_messages_test->setTable("messages_test");
$ins_messages_test->addColumn("datetime", "DATE_TYPE", "POST", "datetime");
$ins_messages_test->addColumn("replied", "STRING_TYPE", "POST", "replied", "1");
$ins_messages_test->addColumn("trash", "STRING_TYPE", "POST", "trash");
$ins_messages_test->addColumn("sender_has", "STRING_TYPE", "POST", "sender_has");
$ins_messages_test->addColumn("reciever_has", "STRING_TYPE", "POST", "reciever_has");
$ins_messages_test->addColumn("reciever", "STRING_TYPE", "POST", "reciever");
$ins_messages_test->addColumn("sender", "STRING_TYPE", "POST", "sender");
$ins_messages_test->addColumn("subject", "STRING_TYPE", "POST", "subject");
$ins_messages_test->addColumn("message", "STRING_TYPE", "POST", "message");
$ins_messages_test->addColumn("recieved", "STRING_TYPE", "POST", "recieved");
$ins_messages_test->setPrimaryKey("id", "NUMERIC_TYPE");

// MOVE IT HERE
$tNGs->addTransaction($ins_messages_test);

// Execute all the registered transactions
$tNGs->executeTransactions();

 

Other than that, go back to documentation for these functions.  Or point us towards them.  I'm interested to know what the heck these are doing, looks interesting.

ive scrapped all my developer toolbox wizard so im faced with my blank page again where ill attempt to code it properly, has anyone any information on sites where i can get the information i need? I also need a query where the users message will insert into a new row, whilst updating another, or is that not possible? thanks

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.