hi,
would you be able to tell me which line goes where in the different php scripts below. Basically what i want is to insert the AccID of the person who logs in with a user name and pw on the first page and store this AccID in the ticket table against newly generated ticket num which happens in the 4th script. soo need a session.
Here is the code. i have been stuck on this problem for about two weeks.
HomePg.php
/* here the user enters their username and password and clicks submit which sends them to Login2.php */
<?php
session_start();
?>
<html><head>
<title>Members Only Login</title>
</head><body>
<?php
@ $db = mysql_pconnect("localhost");
if (!$db)
{
echo "Error: Could not connect to database.";
exit;
}
mysql_select_db("data");
?>
<table border = "0">
<tr>
<td colspan="3" bgcolor="gray" align="center">
<b>Members Only</b>
</td></tr>
<tr>
<td width="33%" align="top">
<b>Already A Member?</b>
<form name="Login Form" method = "get" action = "Login2.php">
<table border="0">
<tr>
<td width="148">Email
</td>
<td>
<input type="text" name=UNameFrm size="30">
</td></tr>
<tr>
<td width = "148">Password
</td>
<td>
<input type="password" name=PW1 size="30">
</td></tr>
<tr>
<td align="center" colspan="2">
<br>
<input type = "submit" value = "Login">
</td></tr>
</table>
</td>
</form>
</td></tr>
</table>
</body></html>
Login2.php
/* Here the user just clicks on the purchase ticket button and this brings them to TimeData.php */
<?php
session_start();
?>
<html><head>
<title>Members Only Login</title>
</head><body>
<?php
if (!$UNameFrm || !$PW1){
print "<script type='text/javascript'>\n";
print "alert('You Must Enter Both Email and Password. Please Go Back and Try Again');\n";
print "</script>";
exit;
}
@ $db = mysql_pconnect("localhost");
if (!$db){
echo "Error: Could not connect to database.";
exit;
}
mysql_select_db("data");
$qry_FindMemDetails = "SELECT * FROM acctbl
WHERE acctbl.Username = '$UNameFrm' AND acctbl.PW = '$PW1'";
$FindMemDetails = mysql_query($qry_FindMemDetails);
$row_FindMemDetails = mysql_fetch_assoc($FindMemDetails);
$totalRows_FindMemDetails = mysql_num_rows($FindMemDetails);
?>
<center>
<table border = "0">
<tr>
<td colspan="3" bgcolor="gray" align="center">
<b>Welcome Back</b>
</td></tr>
<tr>
<td width="33%" align="top">
<b>Click On Buttons Below</b>
<br>
<table border="0">
<tr>
<td width="148">
<input type = "submit" name = TimeData value = "PurchaseTicket" onclick ="window.location.href='TimeData.php';">
</td></tr>
</table>
</td></tr>
</table>
</center>
</body></html>
TimeData.php
/* here the user justs selects how much time and clicks submit which calls Ticket.php */
<?php
session_start();
?>
<html>
<head>
<title>Purchase Time and Data</title>
</head>
<?php
@ $db = mysql_pconnect("localhost");
if (!$db)
{
echo "Error: Could not connect to database.";
exit;
}
mysql_select_db("demodata");
?>
<table border = "0">
<form name="Purchase Form" method="post" action="Ticket.php">
<tr>
<td colspan="3" bgcolor="gray" align="center">
<b>Purchase ticket</b>
</td>
</tr>
<tr>
<td>
<center>
<table>
<tr>
<td>
<input type="radio" name=TimeDataFrm value="Buy Time" checked>Buy Time
</td>
</tr>
<tr>
<td width = "178">
<select name=OptionFrm>
<?php
$qry = "SELECT TimeData, Cost, Description FROM Chrgtbl WHERE TimeData Like '%mins%'";
$result = mysql_query($qry);
while($row = mysql_fetch_assoc($result))
echo "<option value = '".$row['TimeData']."'>".$row['TimeData']." || ⬠".$row['Cost']." || ".$row['Description']."</option>";
?>
</select>
</td>
</tr>
</table>
</center>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type = "submit" name = PurchaseTicket value = "Purchase a Ticket">
</td>
</tr>
</form>
</table>
</body>
</html>
Ticket.php
/* when the user clicks submit button on TimeData.php this script generates a random number and inserts it into the database */
<?php
session_start();
?>
<html>
<head>
<title>Purchase Ticket</title>
</head>
<body>
<?php
@ $db = mysql_pconnect("localhost");
if (!$db)
{
echo "Error: Could not connect to database.";
exit;
}
mysql_select_db("data");
/* Random Function */
function RandomNumber($length)
{
global $Random;
$Random = srand((double)microtime()*1000000);
$data = "AbcDE123GHIJK4LMN567QRSTU89VWXYZ";
$data .= "aBCdefghijklmn123opq45rs67tuv89wxyz";
$data .= "0FGH45OP89";
for($i = 0; $i < $length; $i++)
{
$Random .= substr($data, (rand()%(strlen($data))), 1);
}
echo "$Random <br>";
}
RandomNumber(8);
$TodaysDate = date("Y-m-d h:m:s");
echo "$TodaysDate <br>";
$qry = "select ChrgID from chrgtbl where chrgtbl.TimeData = '$OptionFrm'";
$result = mysql_query($qry) or die(mysql_error());
$row = mysql_fetch_object($result);
/* INSERT DETAILS INTO TICKET TABLE */
$insert = "insert into tickettbl (AccID, ChrgID, TicketNo, TimeData, RecDate)
values ('".$_SESSION['AccID']."', '$row->ChrgID', '$Random', '$OptionFrm', '$TodaysDate')";
$result = mysql_query($insert) or die(mysql_error());
if ($result)
echo "Entered";
?>
</body>
</html>
**********************************************
what i want to do is have a session that stores the username and password of the person when they login at the home page and use this info to do a select query in the ticket.php that will select the accid from the acctbl where the username equals that of the person logging in.
Please note that the Field name in the db are called Username & PW and the textboxes that the users types in to are called $UNameFrm & $PW1.
Can you please help me i am so lost.
thanks in advanced,
scoobie
|