This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Dreamweaver > March 2004 > outputting form data





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 outputting form data
tgwarrior

2004-03-09, 12:29 pm

I'm using Dreamweaver MX 2004 with PHP/MySQL.

I have an insert record (subscription) form. I would like to give the user
the data they typed into the form displayed in a page after they submit the
form. i.e. I want to output to a new URL the data of ONE record - the record
that user just added to the database.

How can I do this?

Steve Fleischer

2004-03-09, 12:30 pm

On Tue, 9 Mar 2004 15:55:53 +0000 (UTC), tgwarrior wrote:

> I'm using Dreamweaver MX 2004 with PHP/MySQL.
>
> I have an insert record (subscription) form. I would like to give the user
> the data they typed into the form displayed in a page after they submit the
> form. i.e. I want to output to a new URL the data of ONE record - the record
> that user just added to the database.
>
> How can I do this?


Someone else asked this recently and this is the example I posted. I think
you'll see how it is done (using session variables):


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, 10-Mar-04 12:03:49 AM
Steve Fleischer

2004-03-09, 1:30 pm

On Wed, 10 Mar 2004 00:05:02 +0800, Steve Fleischer wrote:

> <td> <input name="secret" type="hidden" id="secret"
> value="flobble"></td>


BTW, this part of the form page is not necessary (it was for something else
I was testing and forgot to remove!!)
--
Steve
www dot flyingtigerwebdesign dot com
Hong Kong, 10-Mar-04 12:44:23 AM
Sponsored Links


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