Skip to main content
Participant
August 20, 2007
Question

Insert Recordset - Redirect Url not working - PHP

  • August 20, 2007
  • 6 replies
  • 882 views
I'm trying to insert a record then jump to a confirmation page, but I can't seem to get it to work. The record is inserted but the page doesn't redirect. I get no error message. Here's the PHP code:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addform")) {
$insertSQL = sprintf("INSERT INTO bios (bio_personname, bio_persontitle) VALUES (%s, %s)",
GetSQLValueString($_POST['bio_personname'], "text"),
GetSQLValueString($_POST['bio_persontitle'], "text"));

mysql_select_db($database_connCasey_fcs, $connCasey_fcs);
$Result1 = mysql_query($insertSQL, $connCasey_fcs) or die(mysql_error());

$insertGoTo = "/faculty/bios/confirm_test.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
This topic has been closed for replies.

6 replies

Participant
August 29, 2007
Thanks, David. Tremendous help!
Inspiring
August 21, 2007
casey_g wrote:
> Thanks again. This is the right track. When I copy the connection code
> directly into the insert record page, it does redirect correctly.
> But I can't find any extra spaces or newlines in either the insert record page
> or the Connection script - is there anything else to look for?

If it works when you copy the connection code into the insert record
page, there's only one answer: there is something in the connection
script that is causing it. Place your cursor immediately to the left of
the opening PHP tag in the connection script and press Backspace several
times. Click as far down on the page as you can after the closing PHP
tag, and press Backspace until your cursor is directly to the right of
the closing angle bracket.

The usual giveaway is that line numbering extends below the closing tag
of the connection file.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Participant
August 29, 2007
If I can add to this discussion, I had the exact problem that casey_g described. When I copied the configuration code into the head of my insert page, things worked as expected. I also checked my connection.php file and found no extraneous whitespaces.

It may have something to do with the format of the code that Dreamweaver enters into the page when using the Server Behaviors feature. Here is what is inserted at the beginning of my page:
casey_gAuthor
Participant
August 21, 2007
David,
Thanks again. This is the right track. When I copy the connection code directly into the insert record page, it does redirect correctly.
But I can't find any extra spaces or newlines in either the insert record page or the Connection script - is there anything else to look for?
Inspiring
August 21, 2007
casey_g wrote:
> Thank you, David, for the quick reply. Unfortunately, the insert record page still doesn't jump to the confirmation page, even with the full URL.

At a guess, then, you probably have display_errors turned off, which is
preventing the display of a "headers already sent" error message. If
there is any output to the browser before header(), the page cannot be
redirected. This is caused by space in front of the opening PHP tag, or
new lines at the bottom of any include files, such as the Connection file.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
casey_gAuthor
Participant
August 21, 2007
Thank you, David, for the quick reply. Unfortunately, the insert record page still doesn't jump to the confirmation page, even with the full URL.
Inspiring
August 20, 2007
casey_g wrote:
> $insertGoTo = "/faculty/bios/confirm_test.php";

This should be a fully qualified URL, complete with http:// and the
domain name.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/