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));
}
Help displaying second form
Moderator: General Moderators
Help displaying second form
Last edited by krlsoft on Sat Jan 24, 2009 7:44 pm, edited 1 time in total.
Re: Help displaying second form
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.
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
Code: Select all
Code: Select all
This point still stands.
Re: Help displaying second form
What error message?
Re: Help displaying second form
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
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
That has absolutely nothing to do with the code you posted.
Re: Help displaying second form
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.
$insertGoTo= "/Index5.php" it works the error only throws when I try to have the form display the record.
Re: Help displaying second form
If the problem happens when it tries to display the record then it's that code that has a problem.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.
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
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);
?>
<?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);
?>