My issue is when i submit my form my outcome is unsucessfull.
<?php
class model {
function __construct($url, $root, $common_model, $common_view, $alt_root) {
$this->url = $url;
$this->root = $root;
$this->common_model = $common_model;
$this->common_view = $common_view;
$this->alt_root = $alt_root;
$this->loader();
}
function loader() {
if ($this->common_model->search_get($this->url,'Log_An_Invoice')=='View_An_Invoice') {
$this->View_An_Invoice();
} elseif ($this->common_model->search_get($this->url,'Log_An_Invoice')=='Invoice_Logged') {
$this->Invoice_Logged();
} else {
$this->Log_An_Invoice();
}
}
function Log_An_Invoice() {
$this->common_view->template_header();
$this->common_view->cams_style();
$this->common_view->template_body();
$this->common_view->page_title('Log An Invoice', 'Log_An_Invoice');
echo '<div class="tabPane">';
echo '<div class="tabActive" onclick="window.location.href=\\''.$this->root.'Log_An_Invoice\\';"><span><b>Log An Invoice</b></span><img src="'.$this->root.'images/gui/tab_right_active.gif" /></div>';
if (($_COOKIE['talent_user_email_address'] == "paul.jackson@talent.co.uk")){
echo '<div id="left_actions" class="tabInactive" onclick="window.location.href=\\''.$this->root.'Log_An_Invoice/View_An_Invoice\\';" onmouseover="document.getElementById(\\'left_actions\\').className=\\'inactiveTabOver\\';document.getElementById(\\'right_actions\\').src=\\''.$this->root.'images/gui/tab_right_over.gif\\';" onmouseout="document.getElementById(\\'left_actions\\').className=\\'tabInactive\\';document.getElementById(\\'right_actions\\').src=\\''.$this->root.'images/gui/tab_right_inactive.gif\\';"><span><b>View An Invoice</b></span><img id="right_actions" src="'.$this->root.'images/gui/tab_right_inactive.gif" /></div>';
} else {}
echo '</div>';
echo '
<form class="form-signin" role="form" action="window.location.href=\\''.$this->root.'Log_An_Invoice/Invoice_Logged\\';"method="POST">
<h2 class="form-signin-heading" style="text-align: center;">Invoice Form</h2>
<select name="InvoiceFrom" id="InvoiceFrom" type="Text" class="form-control" required autofocus>
<option value="" selected>Please Select One...</option>
<option value="Talent">Talent</option>
<option value="Redwood">Redwood</option>
<option value="Hillingdon">Hillingdon</option>
</select>
<input name="InvoiceTo" type="text" class="form-control" placeholder="Invoice To" required>
<input name="ContactName" type="text" class="form-control" placeholder="Contact Name" required>
<input name="ContactNumber" type="text" class="form-control" placeholder="Contact Number" required>
<input name="Email" type="email" class="form-control" placeholder="Contact Email" required>
<textarea name="InvoiceAddress" type="text" class="form-control" placeholder="Contact Address" rows="5" required></textarea>
<input name="PoNo" type="text" class="form-control" placeholder="PO No" required>
<textarea name="Details" type="text" class="form-control" placeholder="Invoice Details (Description)" rows="5" required></textarea>
<div class="input-group">
<span class="input-group-addon">£</span>
<input name="InvoiceAmount" class="form-control" placeholder="Total Amount" type="number" required>
</div>
<label class="checkbox" >
<input type="checkbox" value="0" style="text-align: center;" required> I accept that the following information is correct.
</label>
<button type="button" type="submit" >Log Invoice</button>
</form>';
$this->common_view->template_footer();
}
function View_An_Invoice() {
$this->common_view->template_header();
$this->common_view->cams_style();
$this->common_view->template_body();
$this->common_view->page_title('View An Invoice', 'View_An_Invoice');
echo '<div class="tabPane">';
echo '<div id="left_actions" class="tabInactive" onclick="window.location.href=\\''.$this->root.'Log_An_Invoice\\';" onmouseover="document.getElementById(\\'left_actions\\').className=\\'inactiveTabOver\\';document.getElementById(\\'right_actions\\').src=\\''.$this->root.'images/gui/tab_right_over.gif\\';" onmouseout="document.getElementById(\\'left_actions\\').className=\\'tabInactive\\';document.getElementById(\\'right_actions\\').src=\\''.$this->root.'images/gui/tab_right_inactive.gif\\';"><span><b>Log An Invoice</b></span><img id="right_actions" src="'.$this->root.'images/gui/tab_right_inactive.gif" /></div>';
echo '<div class="tabActive" onclick="window.location.href=\\''.$this->root.'Log_An_Invoice/View_An_Invoice\\';"><span><b>View An Invoice</b></span><img src="'.$this->root.'images/gui/tab_right_active.gif" /></div>';
echo '</div>';
// Make a MySQL Connection
mysql_connect("localhost", "Form", "") or die(mysql_error());
mysql_select_db("talent_intranet") or die(mysql_error());
// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM Form")
or die(mysql_error());
echo '<div style="margin-left:5px;margin-right:5px;" class="search_results_header" align="left">
<table style="border-collapse:collapse;" cellpadding="2" cellspacing="0" border="0" width="100%">
<tbody><tr>
<td colspan="7" class="td_header" height="30" width="100%"><b>Approvals</b><div style="float:right;">
<button type="button" href="www.talnet.co.uk/intranet/Log_An_Invoice">Log An Invoice</button><button type="button" href="www.talnet.co.uk/intranet/">Home</button>
</div></td>
</tr>
<tr>
<td class="td_header" height="30" width="4%">ID</td>
<td class="td_header" height="30" width="6%">Invoice From</td>
<td class="td_header" height="30" width="15%">Invoice To</td>
<td class="td_header" height="30" width="7%">Invoice Address</td>
<td class="td_header" height="30" width="6%">Contact Name</td>
<td class="td_header" height="30" width="7%">Contact Number</td>
<td class="td_header" height="30" width="22%">Email</td>
<td class="td_header" height="30" width="12%">Po No</td>
<td class="td_header" height="30" width="10%">Details</td>
<td class="td_header" height="30" width="10%">Invoice Amount</td>
<td class="td_header" height="30" width="10%">Date Submitted</td>
<td class="td_header" height="30" width="10%">Submitted By</td>
</tr>
</tbody></table>
</div>
<div style="padding-left:5px;padding-right:5px;padding-bottom:5px;" align="left">
<div class="search_results" style="height:175px;overflow-y:auto;overflow-x:auto;" align="left">
<table style="border-collapse:collapse;" cellpadding="2" cellspacing="0" width="100%">
<tbody>';
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo '<tr><td class="td_header" height="30" width="15%"><font size="1">';
echo $row['id'];
echo '</font></td><td class="td_header" height="30" width="15%"><font size="1">';
echo $row['InvoiceFrom'];
echo '</font></td><td class="td_header" height="30" width="15%"><font size="1">';
echo $row['InvoiceTo'];
echo '</font></td><td class="td_header" height="30" width="25%"><font size="1">';
echo $row['InvoiceAddress'];
echo '</font></td><td class="td_header" height="30" width="15%"><font size="1">';
echo $row['ContactName'];
echo '</font></td><td class="td_header" height="30" width="15%"><font size="1">';
echo $row['ContactNumber'];
echo '</font></td><td class="td_header" height="30" width="15%"><font size="1">';
echo $row['Email'];
echo '</font></td><td class="td_header" height="30" width="15%"><font size="1">';
echo $row['PoNo'];
echo '</font></td><td class="td_header" height="30" width="15%"><font size="1">';
echo $row['Details'];
echo '</font></td><td class="td_header" height="30" width="15%"><font size="1">£';
echo $row['InvoiceAmount'];
echo '</font></td><td class="td_header" height="30" width="15%"><font size="1">';
echo $row['Submitted'];
echo '</font></td><td class="td_header" height="30" width="15%"><font size="1">';
echo $row['SubmittedBy'];
echo "</font></td></tr>";
}
echo "</tbody></table></div></div>";
mysql_close();
$this->common_view->template_footer();
}
function Invoice_Logged() {
$this->common_view->template_header();
$this->common_view->cams_style();
$this->common_view->template_body();
$this->common_view->page_title('Invoice Logged', 'Invoice_Logged');
echo '<div class="tabPane">';
echo '<div id="left_actions" class="tabInactive" onclick="window.location.href=\\''.$this->root.'Log_An_Invoice\\';" onmouseover="document.getElementById(\\'left_actions\\').className=\\'inactiveTabOver\\';document.getElementById(\\'right_actions\\').src=\\''.$this->root.'images/gui/tab_right_over.gif\\';" onmouseout="document.getElementById(\\'left_actions\\').className=\\'tabInactive\\';document.getElementById(\\'right_actions\\').src=\\''.$this->root.'images/gui/tab_right_inactive.gif\\';"><span><b>Log An Invoice</b></span><img id="right_actions" src="'.$this->root.'images/gui/tab_right_inactive.gif" /></div>';
if (($_COOKIE['talent_user_email_address'] == "paul.jackson@talent.co.uk")){
echo '<div id="left_actions" class="tabInactive" onclick="window.location.href=\\''.$this->root.'Log_An_Invoice/View_An_Invoice\\';" onmouseover="document.getElementById(\\'left_actions\\').className=\\'inactiveTabOver\\';document.getElementById(\\'right_actions\\').src=\\''.$this->root.'images/gui/tab_right_over.gif\\';" onmouseout="document.getElementById(\\'left_actions\\').className=\\'tabInactive\\';document.getElementById(\\'right_actions\\').src=\\''.$this->root.'images/gui/tab_right_inactive.gif\\';"><span><b>View An Invoice</b></span><img id="right_actions" src="'.$this->root.'images/gui/tab_right_inactive.gif" /></div>';
} else {}
echo '<div class="tabActive" onclick="window.location.href=\\''.$this->root.'Log_An_Invoice/Invoice_Logged\\';"><span><b>Invoice Logged</b></span><img src="'.$this->root.'images/gui/tab_right_active.gif" /></div>';
echo '</div>';
$Submitted = date("d-m-Y");
$SubmittedBy = $_COOKIE['talent_user_email_address'];
$errors = array();
$required = array(
'InvoiceFrom' =>'This is required',
'InvoiceTo' =>'This is required',
'InvoiceAddress'=>'This is required',
'ContactName' =>'This is required',
'ContactNumber' =>'This is required',
'Email' =>'This is required',
'PoNo' =>'This is required',
'Details' =>'This is required',
'InvoiceAmount' =>'This is required'
);
if ('POST' === $_SERVER['REQUEST_METHOD'])
{
foreach ($required as $field => $error)
{
$isEmpty = 0 == strlen(trim($_POST[$field]));
if ($isEmpty) {
$errors[] = $error;
}
}
if ( ! filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Email must be a valid email address';
}
if ( ! preg_match('~^[0-9.]+$~i', $_POST['InvoiceAmount'])) {
$errors[] = 'Invoice amount value is invalid';
}
if(!isset($_POST['InvoiceFrom'])){
$errors[] = '<li>You forgot to select the company!</li>';
}
if (empty($errors))
{
$con = mysql_connect("localhost","Form","","talent_intranet");
if(!$con){
die('Could not connect: ' .mysql_error());
}
$db_selected = mysql_select_db("talent_intranet", $con);
if (!$db_selected){
die ("Can\\'t select db : " . mysql_error());
}
$sql = sprintf(
"INSERT INTO
Form
(InvoiceFrom, InvoiceTo, InvoiceAddress, ContactName, ContactNumber, Email, PoNo, Details, InvoiceAmount, Submitted, SubmittedBy )
VALUES
('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s','$Submitted','$SubmittedBy');",
mysql_real_escape_string($_POST['InvoiceFrom']),
mysql_real_escape_string($_POST['InvoiceTo']),
mysql_real_escape_string($_POST['InvoiceAddress']),
mysql_real_escape_string($_POST['ContactName']),
mysql_real_escape_string($_POST['ContactNumber']),
mysql_real_escape_string($_POST['Email']),
mysql_real_escape_string($_POST['PoNo']),
mysql_real_escape_string($_POST['Details']),
mysql_real_escape_string($_POST['InvoiceAmount'])
);
$res = mysql_query($sql, $con);
}
if(!$res){
die ("Can\\'t run query : " . mysql_error());
}
$errors[] = mysql_error($con);
mysql_close($con);
echo'<h1>Your Invoice Was Logged Successfully!</h1>';
echo'<button type="button" href="www.talnet.co.uk/intranet/Log_An_Invoice">Log An Invoice</button> <br> <button type="button" href="www.talnet.co.uk/intranet/">Home</button> ';
} else {
echo'<h1>Your Invoice Was Not Successful!</h1>';
echo'<button type="button" onclick="window.location.href=\\''.$this->root.'Log_An_Invoice\\';">Retry</button> <br> <button type="button" onclick="window.location.href=\\''.$this->root.'\\';">Home</button> ';
echo'<h2>Please contact your system administrator. Inform of the following message.</h2>';
if (count($errors)){
foreach ($errors as $error){
echo $errors;
}
}
error_reporting(E_ALL);
}
$this->common_view->template_footer();
}
}
?>
None of Invoice_Logged funtion is wrong. i dont understand how make a form post to a function that injects.
Help please.
Thanks
-Jamie