Help with form action (PHP process)
Posted: Mon Sep 13, 2010 3:59 am
Hi all, I'm Arnora. Very new to this forum and PHP in general. (Not fantastic with HTML either but needed to learn some for work)
I have been tasked with building a private area on a website for a Distribution company.
Now I have built this in HTML and using a seperate program created a PHP page to process the Login form and another to process the Distributors job selection.
Since that I have managed to fine-tune the Login page, using PHP, to select data from the MySQL database, confirm the user entered data matches and to redirect (woohoo). The login page also stores some session information, and stores some of that info into another table on the database.
The following page uses this session info to ensure authorisation and to echo the distributors name, a simple Welcome.
Though this actually took me a while to get right as on the login page I had missed a single underscore and had, $logname=$POST['lUsername'];, instead of $logname=$_POST['lUsername'];. This caused my second page sql request to return, well, nothing. (Drove me mad).
And so on to the job selections. The following code selects info from the database based on a date range, defined in the session info. Then displays this information in a table with a form field for the user to put his email address in.
Now this does look really nice on the page. A nice table with form field to select the jobs and a button to confirm selection.
As you can see the form action is currently blank (previously mentioned HTML page is currently in use) I would like to process this form and insert the email address supplied into the correct row in the Username column. Change the correct row in the Available column to show "No" in replace of "Yes". email the selected job/jobs to our info address. And finally redirect the user to success.htm. (what a mouthfull)
Now am stuck I honestly can't see how to do this. I've thought about re-writing the page, removing the selection boxes and form from this table and creating another form underneath where the user can put ID number into a form field and submit that instead. I can then update the correct row based on id number used and session stored Username. But I still have the issue of emailing this info from there.
Is this a better option? I don't really want to do this (I love the layout too much and besides my boss is watching and he likes it too) but needs must I suppose.
If anyone can help me here I would be (so very very very much) apreciative.
Thank you all
Arnora
I have been tasked with building a private area on a website for a Distribution company.
Now I have built this in HTML and using a seperate program created a PHP page to process the Login form and another to process the Distributors job selection.
Since that I have managed to fine-tune the Login page, using PHP, to select data from the MySQL database, confirm the user entered data matches and to redirect (woohoo). The login page also stores some session information, and stores some of that info into another table on the database.
Code: Select all
{
$_SESSION['auth']="yes";
$logname=$_POST['lUsername'];
$_SESSION['logname'] = $logname;
$today = date("Y-m-d H:i:s");
$importantdate = date("Y-m-d", strtotime("+28 days"));
$_SESSION['importantdate'] = $importantdate;
$now = date("Y-m-d");
$_SESSION['now'] = $now;
header("Location: current.php");
$sql = "INSERT INTO Login (Username,LoginTime)
VALUES ('$logname','$today')";
mysql_query($sql) or die("Can't execute query");
}Code: Select all
<?php
session_start();
if (@$_SESSION['auth'] !="yes")
{
header("location:index.php");
exit();
}
include("db.inc");
$connection = mysql_connect($hostname,$username,$password)
or die ("Could not connect to server");
$db = mysql_select_db($database,$connection)
or die ("Could not connect to database");
$sql = "SELECT FirstName,LastName FROM Distributors
WHERE Username ='{$_SESSION['logname']}'";
$result = mysql_query($sql)
or die("Couldn't execute query for result");
if(mysql_num_rows($result)>0) //there are results returned
{
$row = mysql_fetch_array($result);
extract($row);
}
?>
a few lines of HTML
<?php echo " Welcome $FirstName $LastName "; ?>And so on to the job selections. The following code selects info from the database based on a date range, defined in the session info. Then displays this information in a table with a form field for the user to put his email address in.
Code: Select all
<?php
$sql2 = "SELECT * FROM Available_Workload
WHERE StartDate BETWEEN '{$_SESSION['now']}'
AND '{$_SESSION['importantdate']}'
AND Available='Yes' ORDER BY ID";
$result2 = mysql_query($sql2)
or die ("Couldn't execute query for result2");
$row = mysql_fetch_array($result2) or die(mysql_error());
/*Display results in a table*/
echo "<form action=' ' method='post' name='select' id='select'>";
echo "<table cellspacing='2' border='0' cellpadding='0' width='702' style='text-align: center' style='font-size: smaller'>";
echo "<tr>\n";
echo "<td width='107'><h3>StartDate</h3></td>\n";
echo "<td width='132'><h3>EndDate</h3></td>\n";
echo "<td width='156'><h3>Areas</h3></td>\n";
echo "<td width='95'><h3>Quantity</h3></td>\n";
echo "<td width='200'><h3>Email Selection</h3></td>\n";
echo "</tr>\n";
echo "<tr>
<td colspan='5' align='center'>
<hr>
</td>
</tr>\n";
while($row = mysql_fetch_array($result2,MYSQL_ASSOC))
{
$StartDate = date_create($row['StartDate']);
$f_StartDate = date_format(date_create($row['StartDate']), 'j,M,Y');
$EndDate = date_create($row['EndDate']);
$f_EndDate = date_format(date_create($row['EndDate']), 'j,M,Y');
/*Display row for each available job*/
echo "<tr>\n";
echo "<td>$f_StartDate</td>\n";
echo "<td>$f_EndDate</td>\n";
echo "<td>{$row['Areas']}</td>\n";
echo "<td>{$row['Quantity']}</td>\n";
echo "<td><input name='{$row['ID']}' type='text' size='20'></td>\n";
echo "</tr>\n";
}
echo "<tr>
<td colspan='6'>
<hr>
</td>
</tr>\n";
echo "<tr>
<td colspan='6' align='center'>
<input type='submit' name='submit' id='submit' value='Confirm Selection'>
</td>
</tr>\n";
echo "</table></form>\n";
?>As you can see the form action is currently blank (previously mentioned HTML page is currently in use) I would like to process this form and insert the email address supplied into the correct row in the Username column. Change the correct row in the Available column to show "No" in replace of "Yes". email the selected job/jobs to our info address. And finally redirect the user to success.htm. (what a mouthfull)
Now am stuck I honestly can't see how to do this. I've thought about re-writing the page, removing the selection boxes and form from this table and creating another form underneath where the user can put ID number into a form field and submit that instead. I can then update the correct row based on id number used and session stored Username. But I still have the issue of emailing this info from there.
Is this a better option? I don't really want to do this (I love the layout too much and besides my boss is watching and he likes it too) but needs must I suppose.
If anyone can help me here I would be (so very very very much) apreciative.
Thank you all
Arnora