thanks for reply. The form inserts the record correctly but throws the error when redirecting to new form with record. Here's the code for the entire form:
<?php require_once('Connections/test.php'); ?>
<?php
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_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO bkmess (Title) VALUES (%s)",
GetSQLValueString($_POST['textfield'], "text"));
mysql_select_db($database_test, $test);
$Result1 = mysql_query($insertSQL, $test) or die(mysql_error());
$insertGoTo = "/Index5.php?recordid=".$row_test_results['id'];
//?recordid="$row_test_results['id'];
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_test_results = "1";
if (isset($_GET['recordid'])) {
$colname_test_results = (get_magic_quotes_gpc()) ? $_GET['recordid'] : addslashes($_GET['recordid']);
}
mysql_select_db($database_test, $test);
$query_test_results = sprintf("SELECT * FROM bkmess WHERE id = %s ORDER BY id DESC", $colname_test_results);
$test_results = mysql_query($query_test_results, $test) or die(mysql_error());
$row_test_results = mysql_fetch_assoc($test_results);
$totalRows_test_results = mysql_num_rows($test_results);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {font-family: "Agency FB"}
-->
</style>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="POST" name="Insertform" id="Insertform">
<p> </p>
<h3 align="center">
<span class="style1">Title</span>:
<input name="textfield" type="text" size="70">
<input type="submit" name="Submit" value="Submit">
</h3>
<p> </p>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
<?php
mysql_free_result($test_results);
?>