Jump to content

Recommended Posts

Hi guys, this sounds very complicated to me but i wold really appreciate any help and warning now, it may be a bit of a long read.

 

Thanks to much help here i have solved most problems but have a new task, upon a form submission i need it too create a new .php page from a template.php page i already have. The name of the new page needs to reflect a few details input into the form. At the moment the page name is in the following format;

ref&surname=(customer last name)

&on= (order number)

&date= (order date)

so it may look something like; ''ref&surname=smith&on=123456789&date=01012011.php''

 

I have a script that is generating this when the customer logs in by typing in there details, that's why it looks so complicated.

 

Can anyone help me get this far? that would be a great start and hopefully i could expand from there

I really have no idea what function i can use to create a new page but i can post the actual page i want to use as a template? I been searching everywhere but can't find anything

 

Here is the template page

<?php include '../../login/dbc.php'; page_protect();?>
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$pagina = $_SERVER['REQUEST_URI'];
$datum = date("d-m-y / H:i:s");
$invoegen = $datum . " - " . $ip . " - " . $pagina . "<br />";

$fopen = fopen("ref&surname=smith&on=10811134151&date=010811.html", "a");
fwrite($fopen, $invoegen);
fclose($fopen);

$username = "admin";
$password = "admin";

if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {

?>
<?php
mysql_connect("xxxxxxxxxx", "xxxxxxxxxx", "xxxxxxxxxxxxxxx") or die( "Unable to connect to database");
mysql_select_db("xxxxxxxxxxxxx") or die( "Unable to select database");
$result = mysql_query("SELECT * FROM orderTable") 
?>
<!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=utf-8" />
<title>xxxxxxxxxxxx - Invoice</title>

<link rel="stylesheet" href="../../css/gradient.css" />
<link rel="stylesheet" href="../../css/menu.css" />
<link rel="stylesheet" href="../../css/slider_style.css" />
<link rel="stylesheet" href="../../css/poll_styles.css" />
<link rel="stylesheet" href="../../css/style.css" />

<script language="javascript">
		function confirm_log_in()
		{
			return confirm('By logging in, you agree the details above are correct');
		}
  </script>
<style type="text/css">
body {
background-color: #DDEEF6;
}
</style>
</head>
<body>

<table width="612" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="center"><p><img src="../../images/catalogue/orderstatus_title.png" width="400" height="100" alt="order"><br>
                      </p></td>
                  </tr>
                <tr>
                    <td align="center"><hr /></td>
                  </tr>
                <tr>
                    <td align="center"><table width="40%" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                          <td colspan="2"><?php
					// unique customer order number
				$sql="SELECT * FROM orderTable WHERE orderNum = '10811134151' AND userId = '{$_SESSION['user_id']}'";
					if ($query=@mysql_query($sql)) {
					if (mysql_num_rows($query) > 0) {
					while ($req=mysql_fetch_array($query)) {
?></td>
                      </tr>
                        <tr>
                        <td width="36%" bgcolor="#CDE3F3">Customer name</td>
                        <td width="64%" align="center" bgcolor="#CDE3F3"><input name="textfield7" type="text" disabled="disabled" id="textfield7" value="<?php echo $req['lastName'];?>, <?php echo $req['firstName'];?>"></td>
                      </tr>
                        <tr>
                          <td bgcolor="#CDE3F3">Order Date</td>
                          <td align="center" bgcolor="#CDE3F3"><input name="textfield" type="text" disabled="disabled" id="textfield" value="<?php echo $req['orderDate']; ?> "/></td>
                        </tr>
                        <tr>
                        <td bgcolor="#CDE3F3">Order Number</td>
                        <td align="center" bgcolor="#CDE3F3"><input name="textfield8" type="text" disabled="disabled" id="textfield8" value="<?php echo $req['orderNum'];?>"></td>
                      </tr>
                        <tr>
                        <td colspan="2"><span class="description">
                          <?php
      							}
   								}
   									else {
        								echo "Your Invoice could not be found! Please try again later.";
    							}
							}
								else {
										echo "Query failed ".mysql_error();
							}
							?>
                        </span></td>
                      </tr>
                  </table></td>
                  </tr>
                <tr>
                    <td align="center"><p class="loginform"><span class="errorMessage">If the above details are correct, enter your username and password below.<br>
                      <a href="http://xxxxxxxxxxxxxx/account=account">Not you?</a> Please check your order number and try again. </span><br>
                        <br>
                      </p></td>
                  </tr>
                <tr>
                    <td align="center"><hr /></td>
                  </tr>
                <tr>
                    <td align="center"><form name="form" method="post" action="<?php echo $_SERVER['../../login/PHP_SELF']; ?>">
                        <p>
                        <label for="txtUsername">Username:</label>
                        <br />
                        <input type="text" title="Enter your Username" name="txtUsername" />
                      </p>
                        <p>
                        <label for="txtpassword">Password:</label>
                        <br />
                        <input type="password" title="Enter your password" name="txtPassword" />
                      </p>
                        <p>
                        <input type="submit" onclick="confirm_log_in()" onclick="return log_in()" name="Submit" value="Login" />
                      </p>
                      </form></td>
                  </tr>
                <tr>
                  <td align="center" class="credit">You should have received an email containing your username and password after your order has been processed. Please allow up to 24 hours after submitting your order to receive this email. 
                    Keep your details safe as you will need them each time you want to access this page.<br />
                    <br />
                    If you still have not received your details or cannot log in then please <a href="http://xxxxxxxxxxxxxxx/contact-us">contact us</a>. 
                    By clicking 'Login' you agree that you are the customer stated above or have permission from the customer. For security your IP address will be logged.</td>
  </tr>
                <tr>
                    <td><hr /></td>
                  </tr>
                <tr>
                    <td><?php
}

else {

?></td>
                  </tr>
                <tr>
                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr align="center">
                        <td><table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                              <td colspan="2" align="center"><p>Below you will find details regarding your order, please check everything is correct BEFORE you submit payment. If you need to amend anything please <a href="http://xxxxxxxxxxxxxx/contact-us">contact us</a><br>
                                  <br>
                                  
							<?php
					// unique customer order number
					$sql="SELECT * FROM orderTable WHERE orderNum = '10811134151' AND userId = '{$_SESSION['user_id']}'";
						if ($query=@mysql_query($sql)) {
						if (mysql_num_rows($query) > 0) {
						while ($req=mysql_fetch_array($query)) {
							?>
                                </p></td>
                            </tr>
                            <tr>
                              <td width="100%" colspan="2" align="center"><textarea name="textarea" id="textarea" cols="90" rows="20"><?php echo $req['strMessageBody']; ?></textarea>                                
                              <br></td>
                            </tr>
                            <tr>
                              <td colspan="2" align="center"><hr /></td>
                            </tr>
                            <tr>
                              <td colspan="2" align="center"><br></td>
                            </tr>
                            <tr>
                              <td colspan="2" align="center"><form id="form1" name="form1" method="post" action="http://xxxxxxxxxxxxxx/login/payment/Payment_Information.php">
                                  <table width="60%" border="0" align="center" cellpadding="0" cellspacing="0">
                                    <tr>
                                      <td width="240" align="center"><p>Total in GBP(£)</p></td>
                                      <td width="190"><input name="amount" type="text" id="amount" value="<?php echo $req['total'];?>" readonly="readonly" /></td>
                                    </tr>
                                    <tr>
                                      <td> </td>
                                      <td><label>
                                          <input type="submit" name="submit" id="submit" value="Submit" />
                                        </label></td>
                                    </tr>
                                  </table>
                                  <br />
                              </form></td>
                            </tr>
                            <tr>
                              <td colspan="2" align="center">To confirm invoice amount, please press the submit button above, once your payment has been received your order can begin to be built. <br />                                <br />                              </td>
                            </tr>
                            <tr>
                              <td colspan="2" align="center"><span class="description">
                                <?php
      							}
   								}
   									else {
        								echo "Your Invoice could not be found! Please try again later.";
    							}
							}
								else {
										echo "Query failed ".mysql_error();
							}
							?>
                              </span></td>
                            </tr>
                            </table>
                          <p> </p></td>
                      </tr>
                      </table></td>
  </tr>
                <tr>
                    <td><?php
}
?></td>
                  </tr>
              </table>

</body>
</html>

 

Any ideas to get me started?

A diffrent idea you could use is get the data and dynamicaly put it into the page so you can print from there.

Have everything in a database and use php to insert everything you need from there.

 

Your URL would be something like /invoice.php?id=829769403

and php would pull everything from the DB

$invdata = mysql_query("SELECT * FROM Invoices WHERE AND `ID` = '{$ID}'") or die(mysql_error()); 
while ($data = mysql_fetch_assoc($invdata)) {

     //YOUR PAGE HERE  $data['name']; ect. . .

} ?> 

 

 

So for your title

<title><? echo $data['name']; ?> - Invoice</title>

 

Does this make any sense or do you want a file created for each still?

 

 

Edit: I'm for sure this made no sense but I will gladly explain.

Oh i see what you mean so something like;

<?php
$invdata = mysql_query("SELECT * FROM Invoices WHERE AND `ID` = '{$ID}'") or die(mysql_error()); 
while ($data = mysql_fetch_assoc($invdata)) {

echo $req['lastName'];, echo $req['firstName'];
/n
echo $req['orderDate'];
/n
echo $req['orderNum'];
/n 
/n
echo $req['strMessageBody'];
/n
echo $req['total'];
} 
?> 

 

or am i missing what you mean? also how would i include my login (the bit at the top of the code i posted) and payment script (the form near the bottom) for this?

 

I suppose i would need a unique url for each invoice if you do it this way? but how would it display the data for the correct invoice? I don't understand how to have it display a specific invoice

 

Thanks for the help so far

You have the right idea.

Your login and payment can be just like they are now. Just one question: are you trying to allow everyone but someone with the username or password you have there?

if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) { 

 

To achive this all the form data can be submitted into a database and the invoice page would pull all of it and display it in the correct field. Which by looking at this

$sql="SELECT * FROM orderTable WHERE orderNum = '10811134151' AND userId = '{$_SESSION['user_id']}'";

I assume it is already in a database?

That is just a test invoice, all the details are saved in my database after a customer sends me and order form. I sell products that are made too order so i have to read each invoice, i then email the customer there unique username and password which they can then use to log on and pay for there invoice.

 

What happens is on my website there is a 'my account' page with this form

<form name="form1" id="form1" method="post" action="">
                      <table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                          <td width="52%" align="center"><p>Surname</p></td>
                          <td width="48%"><p>
                              <input name="surname" type="text" class="lowercase" id="surname" size="20" />
                            </p></td>
                        </tr>
                        <tr>
                          <td align="center"><p>Order Number</p></td>
                          <td><p>
                              <input name="on" type="text" class="lowercase" id="on" size="20" />
                            </p></td>
                        </tr>
                        <tr>
                          <td height="36" align="center"><p>Date</p></td>
                          <td><p>
                              <input name="date" type="text" class="lowercase" id="date" size="10"/>
                            <span class="credit">example: 010111</span></p></td>
                        </tr>
                        <tr>
                          <td><p> </p></td>
                          <td><p>
                              <input name="button" type="button" id="button" value="Submit" onclick="makeURL();" />
                            </p></td>
                        </tr>
                      </table>
                  </form>

When all the details are entered in it turns it into a url. I'm not struck on this method but its all i can figure out, i like your way better.

 

I still don't understand how to make the page display the right details though, if i grab all the details how can i get the variable from the user for the right invoice? Wouldn't i need some sort of input box where the customer would type the invoice number?

 

maybe just

<table>
<tr>
<td>order number</td>
<td><form name="form1" method="post" action="">
<label for="orderNum"></label>
<input type="text" name="orderNum" id="orderNum">
</form></td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="submit" id="submit" value="Submit">
</form>
</td>
</tr>
</table>

i don't know what the action would be though. That then takes you to the new page with the order number variable

WHERE orderNum = '$_POST['userNum']' AND userId = '{$_SESSION['user_id']}'

 

Is that right? If not i know im asking a lot but i would really appreciate if you could give me some sort of example to get me going.

 

Thank you.

For the 'My Account' this is the form you would want:

<form name="login" id="login" method="post" action="">
                      <table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                          <td width="52%" align="center"><p>Surname</p></td>
                          <td width="48%"><p>
                              <input name="surname" type="text" class="lowercase" id="surname" size="40" />
                            </p></td>
                        </tr>
                        <tr>
                          <td align="center"><p>Order Number</p></td>
                          <td><p>
                              <input name="on" type="text" class="lowercase" id="on" size="20" />
                            </p></td>
                        </tr>
                        <tr>
                          <td height="36" align="center"><p>Date</p></td>
                          <td><p>
                              <input name="date" type="text" class="lowercase" id="date" size="10"/>
                            <span class="credit">example: 010111</span></p></td>
                        </tr>
                        <tr>
                          <td><p> </p></td>
                          <td><p>
                              <input name="button" type="submit" id="button" value="Submit" onclick="makeURL();" />
                            </p></td>
                        </tr>
                      </table>
                  </form>

You can set the action to go to something like post.php or submit it to the current page (action="")

From there you could do a lookup in the DB

$orderNum = mysql_real_escape_string($_POST['on']);
$surname = mysql_real_escape_string($_POST['surname']);

$check = mysql_query("SELECT * FROM table_name WHERE on = '{$OrderNum}' & `surname` = '{$surname}'")or die(mysql_error());

//Gives error if non-existent
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
	echo "Incorrect Order Number or Surname, please try again."; die;
}

 

From there on you can get all the information from the DB using the information you just gathered and start your while loop.

 

 

<edit>fixed minor error in form</edit>

This is what i have but it doesn't matter what you type into the form to get your order, it just posts everything in the database to the screen  :confused:

 

<?php
session_start();

mysql_connect("xxxxxxx", "xxxxxxxxx", "xxxxxxxxxx") or die( "Unable to connect to invoice database");
mysql_select_db("xxxxxxxxxx") or die( "Unable to select invoice database");

$surname = mysql_real_escape_string($_POST['surname']);
$orderNum = mysql_real_escape_string($_POST['orderNum']);
$check = mysql_query("SELECT * FROM orderTable WHERE orderNum = '{$orderNum}' & lastName = '{$surname}'")or die(mysql_error());

//Gives error if non-existent
$check2 = mysql_num_rows($check);
if ($check2 == 0) 
{
echo "Incorrect Order Number or Surname, please try again."; die;
}
while ($data = mysql_fetch_assoc($check)) 
{
?>
<html>
<head>
<title> <?php echo $data['lastName'];?> - Invoice </title>
</head>
<body>
<table width="100%">
  <tr>
    <td width="14%">First name</td>
    <td width="86%">
      <input name="firstName" type="text" disabled="disabled" id="firstName" value="<?php echo $data['firstName'];?>" />
    </td>
  </tr>
  <tr>
    <td>Lastname</td>
    <td><input name="lastName" type="text" disabled="disabled" id="lastName" value="<?php echo $data['lastName'];?>" /></td>
  </tr>
  <tr>
    <td>Order Number</td>
    <td><input name="orderDate" type="text" disabled="disabled" id="orderDate" value="<?php echo $data['orderNum'];?>" /></td>
  </tr>
  <tr>
    <td>Order Date</td>
    <td><input name="orderNum" type="text" disabled="disabled" id="orderNum" value="<?php echo $data['orderDate'];?>" /></td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Order Details</td>
    <td><label for="textarea"></label>
    <textarea name="textarea" cols="65" rows="10" disabled="disabled" id="textarea"><?php echo $data['strMessageBody']; ?></textarea></td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Total</td>
    <td><input name="total" type="text" id="total" value="<?php echo $data['total'];?>" readonly="readonly" /></td>
  </tr>
</table>
</body>
</html>
<?
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.