Page 1 of 1

Help displaying second form

Posted: Sat Jan 24, 2009 5:20 pm
by krlsoft
Hi,
I am using a form to insert a record in mysql then display the new record in a new form using the following but I I get an error, can anyone help, thanks

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

Re: Help displaying second form

Posted: Sat Jan 24, 2009 5:40 pm
by requinix
Are you going to ask a question or what?
It's nicer when you post replies rather than edit posts. That way we know something's happened. Better than PMing the one person who replied...

And edit your post: put or tags around the code. It helps us, and making things easier for us is in your best interests.
This point still stands.

Re: Help displaying second form

Posted: Sat Jan 24, 2009 8:24 pm
by requinix
What error message?

Re: Help displaying second form

Posted: Sat Jan 24, 2009 9:21 pm
by krlsoft
error message:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Re: Help displaying second form

Posted: Sat Jan 24, 2009 9:40 pm
by requinix
That has absolutely nothing to do with the code you posted.

Re: Help displaying second form

Posted: Sat Jan 24, 2009 9:56 pm
by krlsoft
but if I change it to :
$insertGoTo= "/Index5.php" it works the error only throws when I try to have the form display the record.

Re: Help displaying second form

Posted: Sat Jan 24, 2009 10:44 pm
by requinix
krlsoft wrote:but if I change it to :
$insertGoTo= "/Index5.php" it works the error only throws when I try to have the form display the record.
If the problem happens when it tries to display the record then it's that code that has a problem.
Since you're being redirected, look at the new URL and make sure the ID number is correct. If it is then post the code that retrieves the record data.

Re: Help displaying second form

Posted: Sun Jan 25, 2009 4:40 pm
by krlsoft
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>&nbsp;</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>&nbsp;</p>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
<?php
mysql_free_result($test_results);
?>