This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Dreamweaver > March 2004 > PHP Form Data Not Showing on Redirect Page





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author PHP Form Data Not Showing on Redirect Page
wildwomank

2004-02-29, 5:28 pm

I apologize if this was posted twice...I am fairly new to forums.

I have a form that I wish to not only send the contents to a database, but
also pass the information on to a redirect page. I can get the form to submit
data to the database OR I can get the form to pass the input information to the
redirect page. I CANNOT get the form to do both.

Documentation pointed to implementing a session variable (Dreamweaver TechNote
"How to pass form data from an insert, update or delete page"). In addition to
creating a session variable, the technote tells me that I need to insert some
code in order to instantiate the session variable.

To do this, it says to look for the following line of code:

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] ==
"myForm")) {

then insert the session code below following the code listed above (with my
own variable info, of course):

$FirstName = $HTTP_POST_VARS['txtFirstName'];
session_register("FirstName");

I could see a potential problem as my code did not match the code in the
technote. My code follows below:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add")) {
$insertSQL = sprintf("INSERT INTO events (etitle) VALUES (%s)",
GetSQLValueString($_POST['etitle'], "text"));

However, when I do the hand coding as suggested (inserting it right after the
first line above), the form still enters data into the database, but DOES NOT
pass the form data to the redirect page for display. I also get an error
message from Dreamweaver after entering the new code saying that part of my
code has been deleted. The problem appears to be in the "Action" area of the
form. If it is blank, data get's posted to the database but no data gets
transferred to the redirect page. If it has the redirect's page listed,
nothing gets entered into the database, but data does get transferred to the
redirect page.

I'm about ready to lose it after working on this for two days with absolutely
NO success.

I guess I'm an idiot as I cannot figure out what I am doing wrong?

Thanks for any help you can provide,

K

Steve Fleischer

2004-02-29, 8:28 pm

On Sun, 29 Feb 2004 20:55:28 +0000 (UTC), wildwomank wrote:

> How to pass form data from an insert, update or delete page


OK, I have done this and got it working - it puts the data into mysql and
also sends the values to the redirect page.

Here's a complete example for you look at and adapt for our use:

================The form page (formpage.php)===================
<?php
session_start();
?>
<?php require_once('Connections/PHPCMS.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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"]
== "form1")) {
$insertSQL = sprintf("INSERT INTO testing (testingname, testingselection)
VALUES (%s, %s)",
GetSQLValueString($HTTP_POST_VARS['name'], "text"),
GetSQLValueString($HTTP_POST_VARS['select'],
"text"));

mysql_select_db($database_PHPCMS, $PHPCMS);
$Result1 = mysql_query($insertSQL, $PHPCMS) or die(mysql_error());

$name = $HTTP_POST_VARS['name'];
session_register("name");
$select = $HTTP_POST_VARS['select'];
session_register("select");

$insertGoTo = "formresults.php";
header(sprintf("Location: %s", $insertGoTo));
}
?>
<html>
<head>
<title>form page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="700" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>Test Form</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Insert a name:</td>
<td><input name="name" type="text" id="name" value="Any text here.."
size="35" maxlength="35"></td>
</tr>
<tr>
<td>Make a selection:</td>
<td><select name="select">
<option value="Tea" selected>Tea</option>
<option value="Coffee">Coffee</option>
<option value="Water">Water</option>
<option value="Milk">Milk</option>
<option value="Juice">Juice</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Insert into
Database"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td> <input name="secret" type="hidden" id="secret"
value="flobble"></td>
<td>&nbsp;</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
================The redirect page (formresults.php) =================
<?php
session_start();
?>
<html>
<head>
<title>results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>Your name entry was: <?php echo $_SESSION['name']; ?></p>
<p>Your selection was: <?php echo $_SESSION['select']; ?></p>
</body>
</html>
================End============================
--
Steve
www dot flyingtigerwebdesign dot com
Hong Kong, 01-Mar-04 8:18:07 AM
wildwomank

2004-03-01, 5:29 pm

Steve -

[b]YOY are my hero!!![/b]( It works BEAUTIFULLY!!! Thank you so much for
taking the time to work through my problem. Makromedia needs to replace what
is currently in their technotes with YOUR answer. It would keep everyone from
getting frustrated and wasting so much time.

Your help was TREMENDOUSLY appreciaped.

K

Steve Fleischer

2004-03-01, 10:28 pm

On Mon, 1 Mar 2004 20:47:54 +0000 (UTC), wildwomank wrote:

> Steve -
>
> [b]YOU are my hero!!![/b] It works BEAUTIFULLY!!! Thank you so much for
> taking the time to work through my problem. Macromedia needs to replace what
> is currently in their technotes with YOUR answer. It would keep everyone from
> getting frustrated and wasting so much time.
>
> Your help was TREMENDOUSLY appreciated.


Thanks and you're welcome.

--
Steve
www dot flyingtigerwebdesign dot com
Hong Kong, 02-Mar-04 10:03:51 AM
wildwomank

2004-03-01, 11:28 pm

O.K. I now have my input form working by inputting the data into the database
AND outputting the info to my redirect page (thanks to Steve!). I also have
an "update" page which is taking the "session info" (?) and displaying it in a
form (with all of the correctly chosen drop down menu items pre-selected). So
far, so good. HOWEVER, when I try to "update" the information (i.e. record).
Nothing happens. I am assuming I need to update the record by using the
session variable....but since I'm at a point where I am doing some handcoding
and no longer using Dreamweaver, I'm a little confused as to what components I
am missing.

To assist someone in helping me, here is the entire process I would like to
implement: A user comes to a page and is requested to fill out a form. The
form data gets transferred to a redirect page where the user can see what it is
they entered and confirm whether or not it is acceptable. If the user finds
errors in the data, the user then can select the "modify" page which will allow
them to "update" the data OR go to a "thank you" page where no further
intervention is required. Right now, everything works quite well except the
"udpate" component, where basically nothing happens.

I'm sure that I am missing something obvious.....I just don't know what.

Anything anyone can do to assist me would be tremendously appreciated.

Thank you!



Steve Fleischer

2004-03-02, 1:28 am

On Tue, 2 Mar 2004 03:05:08 +0000 (UTC), wildwomank wrote:

> Anything anyone can do to assist me would be tremendously appreciated.


Hello again! I have changed the original code I sent you and I think it now
does what you want.

i) the original form page is slightly changed in that we now pass the
record number as session data. We must do this because the record number is
auto-incremented when we insert the new record. However, to update that
record on the next page (if necessary) we must know that record number.
hence we pass this (along with the name and drink selection):

$lastID = mysql_insert_id();
session_register("lastID");

ii) the results page is changed to show links asking if all is OK (in which
you go to a non-existant "Thank You" page). If not, the record is recalled
from the database and the data fills a new form. The user can edit his/her
info and Update the db. On updating the user goes to a thank you page.

Hope this is what you meant. Good luck! New pages are below (no thank you
page!):

==============form=============================
<?php
session_start();
?>
<?php require_once('Connections/PHPCMS.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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"]
== "form1")) {
$insertSQL = sprintf("INSERT INTO testing (testingname, testingselection)
VALUES (%s, %s)",
GetSQLValueString($HTTP_POST_VARS['name'], "text"),
GetSQLValueString($HTTP_POST_VARS['select'],
"text"));

mysql_select_db($database_PHPCMS, $PHPCMS);
$Result1 = mysql_query($insertSQL, $PHPCMS) or die(mysql_error());

$name = $HTTP_POST_VARS['name'];
session_register("name");
$select = $HTTP_POST_VARS['select'];
session_register("select");
$lastID = mysql_insert_id();
session_register("lastID");

$insertGoTo = "formresults.php";
header(sprintf("Location: %s", $insertGoTo));
}
?>
<html>
<head>
<title>form page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="700" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>Test Form</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Insert a name:</td>
<td><input name="name" type="text" id="name" value="Any text here.."
size="35" maxlength="35"></td>
</tr>
<tr>
<td>Make a selection:</td>
<td><select name="select">
<option value="Tea" selected>Tea</option>
<option value="Coffee">Coffee</option>
<option value="Water">Water</option>
<option value="Milk">Milk</option>
<option value="Juice">Juice</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Insert into
Database"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
================form result/update================
<?php require_once('Connections/PHPCMS.php'); ?>
<?php session_start(); ?>
<?php
$varID_getLastEntry = "1";
if (isset($_SESSION['lastID'])) {
$varID_getLastEntry = (get_magic_quotes_gpc()) ? $_SESSION['lastID'] :
addslashes($_SESSION['lastID']);
}
mysql_select_db($database_PHPCMS, $PHPCMS);
$query_getLastEntry = sprintf("SELECT * FROM testing WHERE
testing.testingid=%s", $varID_getLastEntry);
$getLastEntry = mysql_query($query_getLastEntry, $PHPCMS) or
die(mysql_error());
$row_getLastEntry = mysql_fetch_assoc($getLastEntry);
$totalRows_getLastEntry = mysql_num_rows($getLastEntry);

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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"]
== "form1")) {
$updateSQL = sprintf("UPDATE testing SET testingname=%s,
testingselection=%s WHERE testingid=%s",
GetSQLValueString($HTTP_POST_VARS['name'], "text"),
GetSQLValueString($HTTP_POST_VARS['select'],
"text"),
GetSQLValueString($HTTP_POST_VARS['recordID'],
"int*));

mysql_select_db($database_PHPCMS, $PHPCMS);
$Result1 = mysql_query($updateSQL, $PHPCMS) or die(mysql_error());

$updateGoTo = "thankyou.html";
header(sprintf("Location: %s", $updateGoTo));
}
?>
<html>
<head>
<title>results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>Record: <?php echo $_SESSION['lastID']; ?></p>
<p>Your name entry was: <?php echo $_SESSION['name']; ?></p>
<p>Your selection was: <?php echo $_SESSION['select']; ?></p>
<p>If this data is correct then click <a href="thankyou.html">here</a>. To
chance your data click <a href="formresults.php?edit=true">here</a></p>
<?php if (isset($HTTP_GET_VARS['edit'])){ ?>
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="700" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>Test Form</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Edit name:</td>
<td><input name="name" type="text" id="name" value="<?php echo
$row_getLastEntry['testingname']; ?>"
size="35" maxlength="35"></td>
</tr>
<tr>
<td>Make another<strong></strong> selection:</td>
<td><select name="select">
<option value="Tea" selected <?php if (!(strcmp("Tea",
$row_getLastEntry['testingselection']))) {echo "SELECTED";} ?>>Tea</option>
<option value="Coffee" <?php if (!(strcmp("Coffee",
$row_getLastEntry['testingselection']))) {echo "SELECTED";}
?>>Coffee</option>
<option value="Water" <?php if (!(strcmp("Water",
$row_getLastEntry['testingselection']))) {echo "SELECTED";}
?>>Water</option>
<option value="Milk" <?php if (!(strcmp("Milk",
$row_getLastEntry['testingselection']))) {echo "SELECTED";}
?>>Milk</option>
<option value="Juice" <?php if (!(strcmp("Juice",
$row_getLastEntry['testingselection']))) {echo "SELECTED";}
?>>Juice</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Update Database"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><input name="recordID" type="hidden" id="recordID" value="<?php echo
$row_getLastEntry['testingid']; ?>"></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
</form>
<?php } ?>
</body>
</html>
<?php
mysql_free_result($getLastEntry);
?>
================end===========================
--
Steve
www dot flyingtigerwebdesign dot com
Hong Kong, 02-Mar-04 12:10:29 PM
wildwomank

2004-03-02, 1:28 am

Steve -

Wow! Thanks a ton for all of your hard work! I will try this code out tomorrow and see how it all shakes out. I have no doubt that it will be perfect!

You're terrific!

K
wildwomank

2004-03-07, 12:28 am

Steve -

Sorry it took me so long to get back to you (it's a long story). I worked
diligently on my code after receiving your email, but had a few problems and
thought that maybe "giving it a rest" would allow me to see the errors in my
code. Sure enough, I did find several problems, but still have a few minor
issues that are not resolving themselves. So, here they are:

After implementing your code (thank you VERY much!), I continue to be
successful in entering data into the database. I am also successful in passing
the information to a "results" page. As you instructed, I have two textual
links at the bottom of my results page that forward to the "update" page (or
actually section, since both the "results" and "update" areas are on the same
physical file). Here is where things get slightly weird in two areas. When I
select my "update" link, I not only get the "results" data but I also get the
"update" data form on the same page as well (instead of just the ?update? data
form/section). However, the ?update? form DOES have the correct data in it?at
least in most of the fields. AND, if I make changes to that data, it DOES
update the correct record in the database (Wahoo!).

My sense is that the reason why BOTH areas are coming up when a user clicks on
the ?edit? button is because of where I have placed the PHP code. Unlike your
example where the ?results? area was not in a table format, my results area is
within a ?table? format. I?m wondering if this might be part of the problem.

Also, three of my dropdown menus are populated with record sets from other
tables and I am unsure how the PHP code is affected by this. Currently, these
form fields are blank on the ?edit? form, although they do come through on the
?results? form.

Thanks to you, I am VERY close to implementing this component as I had hoped
it would operate. I guess I had no idea how complicated it was going to end up
being (I have a friend who routinely does this in ASP).

Thanks tremendously for your expertise. It is SO MUCH appreciated!


Steve Fleischer

2004-03-07, 12:28 am

On Sun, 7 Mar 2004 03:40:58 +0000 (UTC), wildwomank wrote:

> Thanks to you, I am VERY close to implementing this component as I had hoped
> it would operate. I guess I had no idea how complicated it was going to end up
> being (I have a friend who routinely does this in ASP).
>
> Thanks tremendously for your expertise. It is SO MUCH appreciated!


OK, glad to hear that we're almost there! It's lunchtime on Sunday here in
HK and I don't have time to get back to you until tonight. So, give me 9
hours and I'll get back to you with the solution. :-)

--
Steve
www dot flyingtigerwebdesign dot com
Hong Kong, 07-Mar-04 11:45:07 AM
Steve Fleischer

2004-03-07, 12:28 am

On Sun, 7 Mar 2004 11:47:51 +0800, Steve Fleischer wrote:

> On Sun, 7 Mar 2004 03:40:58 +0000 (UTC), wildwomank wrote:


> OK, glad to hear that we're almost there! It's lunchtime on Sunday here in
> HK and I don't have time to get back to you until tonight. So, give me 9
> hours and I'll get back to you with the solution. :-)


Wait, I think I see what you mean regarding the first problem. My page was
just for illustration so I didn't try to hide the results passed to the
page. I can see that in a real page you would want to repaeat the data do
here's what to do:

In the test page code I gave you (formresults.php I believe it was) change
this code segment (just after the body tag and before the form starts):

<p>Record: <?php echo $_SESSION['lastID']; ?></p>
<p>Your name entry was: <?php echo $_SESSION['name']; ?></p>
<p>Your selection was: <?php echo $_SESSION['select']; ?></p>
<p>If this data is correct then click <a href="thankyou.html">here</a>. To
change your data click <a href="formresults.php?edit=true">here</a></p>
<?php if (isset($HTTP_GET_VARS['edit'])){ ?>

to this:

<?php if (!isset($HTTP_GET_VARS['edit'])){ ?>
<p>Record: <?php echo $_SESSION['lastID']; ?></p>
<p>Your name entry was: <?php echo $_SESSION['name']; ?></p>
<p>Your selection was: <?php echo $_SESSION['select']; ?></p>
<p>If this data is correct then click <a href="thankyou.html">here</a>. To
change your data click <a href="formresults.php?edit=true">here</a></p>
<?php } else if (isset($HTTP_GET_VARS['edit'])){ ?>

Originally, the results were shown when this page was displayed to show the
form data to the user. When the user selected to update this information
the page was refreshed with the URL variable edit set to true. This then
displayed the optional section which started with the line:

<?php if (isset($HTTP_GET_VARS['edit'])){ ?>

Now, the form results (which you can put in a table - makes no difference)
at the top of the page ONLY show when the URL variable (edit) is NOT set.
In other words, the page is initially displayed (edit NOT set) and the
results are shown but NOT the update part of the page. If the user clicks
the link the update then the page refreshes (edit IS now set) so the
initial results are hidden but the update form is now visible.

Hope this makes sense!
--
Steve
www dot flyingtigerwebdesign dot com
Hong Kong, 07-Mar-04 11:53:34 AM
Steve Fleischer

2004-03-07, 12:28 am

On Sun, 7 Mar 2004 03:40:58 +0000 (UTC), wildwomank wrote:

> Also, three of my dropdown menus are populated with record sets from other
> tables and I am unsure how the PHP code is affected by this. Currently, these
> form fields are blank on the ?edit? form, although they do come through on the
> ?results? form.


And as for this, populate the dropdowns with a separate query (for each of
the tables). If you go the first one working you'll know how to get the
others working too (same principle). If you have any trouble with this (or
need further explanation) then feel free to email me at:

steve AT flyingtigerwebdesign DOT com

and I'll get back to you in a few hours.

Good luck!
--
Steve
www dot flyingtigerwebdesign dot com
Hong Kong, 07-Mar-04 12:09:28 PM
wildwomank

2004-03-07, 12:28 am

Steve -

No worries. How COOL it must be in Hong Kong and I am MORE than happy to
wait! You have been such an incredible help to me! I don't even know how I can
repay you. Any small trinket you need from the mainland?

Kelly

P.S. The flyingtiger.com website is pretty cool!

wildwomank

2004-03-07, 2:28 pm

Steve -

Everything works BEAUTIFULLY!!! It's PERFECT!! The whole process operates
exactly like I had envisioned. Oh, BTW, the reason why my drop down menus
weren't working is because I had inadvertently deleted the reference to them at
the top of the page. Once I restablished the recordsets, they worked great.

I can't tell you how much I appreciated your help on this. You are one in a
million!

Kelly

P.S. I'm now ready to begin the next component, which is the "Search" mode.
I suspect it won't be as difficult (I hope).

Steve Fleischer

2004-03-07, 3:28 pm

On Sun, 7 Mar 2004 17:54:11 +0000 (UTC), wildwomank wrote:

> I can't tell you how much I appreciated your help on this.


Great news Kelly! Good luck with the rest of the site.
--
Steve
www dot flyingtigerwebdesign dot com
Hong Kong, 08-Mar-04 3:16:42 AM
Steve Fleischer

2004-03-07, 4:28 pm

On Sun, 7 Mar 2004 04:32:42 +0000 (UTC), wildwomank wrote:

> P.S. The flyingtiger.com website is pretty cool!


Thanks! I can take no credit for it, it is all the work of my very talented
partner, DiMa.
--
Steve
www dot flyingtigerwebdesign dot com
Hong Kong, 08-Mar-04 4:02:40 AM
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews