PDA

View Full Version : PHP - passing variables to another page or suggestions


sarconus
10-23-2007, 03:52 PM
Hey guys i am new here and new to coding PHP. I am trying to create an online form that users will fill out and it will display the results on a separate page that can be printed out.

My logic is that when the user clicks the submit button the data would be captured in the DB then i would take the same information from the variables and display them on a new page.

Or

I guess i could use the current session and pass the information to the new page.

I guess my problem is what would be the best logic to use to get my results and what functions do i need to use. I appreciate all your help.

I have gone through the video tutorials which were excellent BTW.

Thanks,
William

domedia
10-23-2007, 04:23 PM
send the variables to the next page <form action="nextpage.php"> and just output wherever you want.

m1a2x3x7
10-23-2007, 05:19 PM
if you want to store things throughout pages use sessions.

sarconus
10-23-2007, 06:26 PM
send the variables to the next page <form action="nextpage.php"> and just output wherever you want.

i have tried that but on my results.php page i get unableto select database. I would assume that i still need my require_once connection.php page or will i not need that since i am passing the variables?

domedia
10-23-2007, 07:07 PM
You don't need a DB at all, you're sending all the data to the next page.

sarconus
10-23-2007, 07:07 PM
Ok ,forget my last post the page came up but no information from the fields were displayed.

I want to use DB so that i can look back in the DB without finding the physical piece of paper. I will supply the code i am using for both pages.

form.php

<?php
require_once("Connections/connection.php"); //database connection

/////////////////////////////////////////////////////////////////////////////////////
$dep = $_POST['dep'];
$manager= $_POST['manager'];
$ename = $_POST['ename'];
$ss = $_POST['ss'];
$agency = $_POST['agency'];
$date = $_POST['date'];
$submit = $_POST['submit'];
///////////////////////////////////////////////////////////////////////////////////////

if ($submit && $dep && $manager && $ename && $ss && $agency && $date){

$query = sprintf ("INSERT into nui (dep, manager, emp_name, ss, agency, date) values ('$dep', '$manager', '$ename', '$ss', '$agency', '$date')");
mysql_query($query) or die (mysql_error());

}elseif ($submit){

echo "One of your fields are empty!";

}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>New User Installation Checklist</title>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif}
.style3 {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 24px;
}
-->
</style>
</head>

<body>
<form id="form1" name="user_info" method="post" action="results.php">

results.php


<?php
require_once("Connections/connection.php"); //database connection

////////////////////////////////////////
$query = sprintf ("SELECT * FROM nui"); //selecting all data from nui table
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
/////////////////////////////////////////

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Results</title>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif}
.style3 {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 24px;
}
-->
</style>
</head>

<body>

<table width="789" height="861" border="0">
<tr>
<th height="104" colspan="3" scope="col"><div align="left"><img src="http://www.newsgroupcentral.com/logo.gif" alt="lgo" width="259" height="76" align="middle" /></div></th>
</tr>
<tr>
<td height="65" colspan="3"><span class="style3">New User Installation Checklist</span></td>
</tr>
<tr>
<td height="65" colspan="3"><div align="left"></div>
<table width="764" border="0">
<tr>
<td width="208">Department:</td>
<td width="546"><label><?php echo $row['dep'];?></label></td>
</tr>
<tr>
<td>Supervisor/Manager:</td>
<td><label><?php echo $row['manager'];?></label></td>
</tr>
<tr>
<td>Employee First Name: </td>
<td><label><?php echo $row['ename'];?></label></td>
</tr>
<tr>
<td>Last 4 of SS#:</td>
<td><label><?php echo $row['ss'];?></label></td>
</tr>
<tr>
<td>Agency &amp; Depot: </td>
<td><label><?php echo $row['agency'];?></label></td>
</tr>
<tr>
<td height="21">Start Date: </td>
<td><?php echo $row['date'];?></td>
</tr>
</table></td>
</tr>
<tr></tr>
<tr>
<td height="57" colspan="3" class="style1">Please check the required software for the above user and submit this form to the IT department at 210-212-8481 Attention IT Dept.&nbsp;After submitting the request, it will be processed in a timely manner and we will send you a confirmation fax or email with the specific details.</td>
</tr>
<tr>
<td width="609">&nbsp;</td>
<td width="123">&nbsp;</td>
<td width="43">&nbsp;</td>
</tr>
</table>
</body>
</html>

davidj
10-24-2007, 07:32 AM
that looks ok

whats the problem