Page 1 of 1

Need true php mysql pro

Posted: Wed Mar 05, 2014 7:44 pm
by dguildner
Ok, so here is the end of my code for the action for a form to update a sale on my database. It works perfect so no problem there. However, where I have the "echo" happening I would rather the form "submit" then go back to the sale it was updating. The item it is updating is in one table called sales on my database. It works fine, but when I submit it the form submits, then clears blank... Need it to go back to the sale. I am using $_GET['id'] to populate the update form.. If you understand php mysql, for real.. looking for help. I will share more code of course.

Code: Select all

       `second_comm`='$_POST[second_comm]',
	 `comm_balance`='$_POST[comm_balance]'
	 WHERE `id` = $_POST[id]";
	mysql_query($u) or die(mysql_error());
	
	echo "You Have Modified This Sale. Click Here $link";
}
?>

Re: Need true php mysql pro

Posted: Wed Mar 05, 2014 8:11 pm
by Celauran
Please do post more code, specifically the form. Is the form's action the same as the page containing the form?

Re: Need true php mysql pro

Posted: Thu Mar 06, 2014 5:57 am
by dguildner
Here is the whole page.. The form is long..sorry. You may want to cope and paste to your text editor. For the main purpose of updating a sale it works great. I would much rather go back to view that sale rather than the form just clearing and staying open..

Code: Select all

<!-- Session start to verify page has been logged in to successfully -->
<?php
	
	session_start();
	
	if(!$_SESSION['loggedin'])
	{
		echo "You are not logged in. Please Log in by clicking Login Button<p>
		<a href=\"../index.php\">Login Here</a>";
		exit;
	}
	$name = $_SESSION['name'];
	$link = $_SESSION['link'];
?>

<?php 
	include 'controllers/connect_mysql.php';
?>

<head>
	<link rel="stylesheet" type="text/css" href="../css/update_sale.css">
</head>

<!-- Connection to Header -->
<?php
	include 'headers/header2_1.php';
?>

<!-- Get data and fill table if submit is not posted -->
<?php
if(!isset($_POST['submit'])) {

	$q = "SELECT * FROM sales WHERE id = $_GET[id]";
	$result = mysql_query($q);
	$user = mysql_fetch_array($result);
}
?>


<!-- Start of Body Content -->
<body>


<!-- Start of EDIT FORM Container -->
<div class="edit_form_container">
	
	<!-- Welcome Username -->
	<h3> Hi <?php print($name);?></h3>
                    

<!-- Beginning of Update Form-->
<form action="update_sale.php" method="post">

<!-- UPDATE BUTTON -->
<input class="update_sale" type="submit" name="submit" value="Update Sale" />

<h3>Sale Details</h3>
<div id="sale_detail_section">
<table>
<tr>
<td>
<!-- Level Selector -->
<label class="label" for="level">Status Level:</label>
<select class="data_cell" id="level" type="text" name="level">
	<option><?php echo $user['level']; ?></option>
	<option>Active</option>
	<option>Cancelled</option>
	<option>Saved</option>
	<option>Complete</option>
</select>
</td>
<td>
<!-- Rep Selector -->
<label class="label" for="rep">Agent Name:</label>
<select class="data_cell" id="rep" type="text" name="rep">
	<option><?php echo $user['rep']; ?></option>
	<option>Mark Herbst</option>
	<option>Larry Probst</option>
	<option>Ken Petranek</option>
	<option>Ralph Smith</option>
</select>
</td>
<td>
<!-- Customer Name -->
<label class="label" for="cname">Customer Name:</label>
<input class="data_cell" id="cname" type="text" name="cname" value="<?php echo $user['cname']; ?>"/>
</td>
</tr>
<tr>
<td>
<!-- Customer City -->
<label class="label" for="city">Customer City:</label>
<input class="data_cell" id="city" type="text" name="city" value="<?php echo $user['city']; ?>"/>
</td>
<td>
<!-- Customer State -->
<label class="label" for="state">Customer State:</label>
<select class="data_cell" id="state" type="text" name="state">
	<option><?php echo $user['state']; ?></option>
	<option>CT</option>
	<option>MA</option>
</select>
</td>
<td>
<!-- Gross Sale -->
<label class="label" for="gross_sale">Gross Sale:</label>
<input class="data_cell" id="gross_sale" type="text" name="gross_sale" value="<?php echo $user['gross_sale']; ?>"/>
</td>
</tr>
<tr>
<td>
<!-- Date Sold -->
<label class="label" for="date_sold">Date Sold:</label>
<input class="data_cell" id="date_sold" type="date" name="date_sold" value="<?php echo $user['date_sold']; ?>"/>
</td>
<td>
<!-- Deposit Amount -->
<label class="label" for="deposit">Deposit:</label>
<input class="data_cell" id="deposit" type="text" name="deposit" value="<?php echo $user['deposit']; ?>"/>
</td>
<td>
<!-- Split Sale Selector -->
<label class="label" for="sale_split">Was sale Split:</label>
<select class="data_cell" id="sale_split" type="text" name="sale_split">
	<option>Sale Not Split</option>
	<option>Mark Herbst</option>
	<option>Larry Probst</option>
	<option>Ken Petranek</option>
	<option>Ralph Smith</option>
</select>
</td>
</tr>
<tr>
</table>
<!-- Comment Area -->
<label class="label" for="comments">Comment Section.. Enter whatever you want sales agent to know about:</label>
<textarea id="comments" type="text" name="comments" cols="100" rows="8"><?php echo $user['comments']; ?></textarea>
</tr>
</div>

<br/>
<h3>Finance Status</h3>
<div id="finance_approval_section">
<table>
<tr>
<td>
<!-- Finance Approval Option -->
<label class="label" for="finace_approved">Was Finance Approved:</label>
<select class="data_cell" id="finance_approved" type="text" name="finance_approved">
	<option>Not Selected</option>
	<option>Pending</option>
	<option>Approved</option>
	<option>Declined</option>
</select>
</td>
<td>
<!--  Maximun Approved For -->
<label class="label" for="max_approved">Max Amount Approved:</label>
<input class="data_cell" id="max_approved" type="text" name="max_approved" value="<?php echo $user['max_approved']; ?>" placeholder="max approved for"/>
</td>
<td>
<!-- Finance Charges -->
<label class="label" for="finance_charges">Finance Charges:</label>
<input class="data_cell" id="finance_charges" type="text" name="finance_charges" value="<?php echo $user['finance_charges']; ?>" placeholder="Finance Charges"/>
</td>
</tr>
<tr>
<td>
<!-- Other Rep Charge Off Gross -->
<label class="label" for="other_rep_off">Other Rep Charge Off Gross:</label>
<input class="data_cell" id="other_rep_off" type="text" name="other_rep_charge_off_gross" value="<?php echo $user['other_rep_charge_off_gross']; ?>" placeholder="Other rep charge off gross"/>
</td>
<td>
<!-- What was Charge Off For -->
<label class="label" for="charge_off_for">Charge Off For:</label>
<input class="data_cell" id="charge-off_for" type="text" name="charge_off_for" value="<?php echo $user['charge_off_for']; ?>" placeholder="Charges for"/>
</td>
<td>
<!-- Adjusted Sale Amount -->
<label class="label" for="adjusted_sale_amount">Adjusted Sale Amount:</label>
<input class="data_cell" id="adjusted_sale_amount" type="text" name="adjusted_sale_amount" value="<?php echo $user['adjusted_sale_amount']; ?>" placeholder="Adjusted Sale Amount"/>
</td>
</tr>
<tr>
<td>
<!-- Type of Financing -->
<label class="label" for="finance_type">Financing Type:</label>
<select class="data_cell" id="finance_type" type="text" name="standard_financing">
	<option>Choose One</option>
	<option>Standard Financing</option>
	<option>Buy Down Finacning</option>
</select>
</td>
<td>
<!-- First Finance Company Used -->
<label class="label" for="first_finance_company">First Finance Company Used:</label>
<select class="data_cell" id="first_finance_company" type="text" name="finance_company_list_1">
	<option>Choose One</option>
	<option>Greensky</option>
	<option>Wells Fargo</option>
	<option>GE</option>
	<option>Carmel</option>
	<option>FFC</option>
</select>
</td>
<td>
<!-- Second Finance Company List -->
<label class="label" for="second_finance_company">Second Finance Company Used:</label>
<select class="data_cell" id="second_finance_company" type="text" name="finance_company_list_2">
	<option>If finance split, choose one</option>
	<option>Greensky</option>
	<option>Wells Fargo</option>
	<option>GE</option>
	<option>Carmel</option>
	<option>FFC</option>
</select>
</td>
</tr>
</table>
</div>

<br/>
<h3>PII Status</h3>
<div id="pii_section">
<table>
<tr>
<td>
<!-- Pre-Installation -->
<label class="label" for="pii">Pre-installation Status:</label>
<select class="data_cell_2" id="pii" type="text" name="pii">
	<option>Choose One</option>
	<option>Not Scheduled</option>
	<option>Scheduled (not done)</option>
	<option>Complete</option>
</select>
</td>
</tr>
</table>
</div>

<br/>
<h3>Cancellation Information</h3>
<div id="cancelled_section">
<table>
<tr>
<td>
<!-- Was Job Cancelled -->
<label class="label" for="cancelled">Was Sale Cancelled:</label>
<select class="data_cell" id="cancelled" type="text" name="cancelled">
	<option>No</option>
	<option>Yes</option>
</select>
</td>
<td>
<!-- Cancellation Reason -->
<label class="label" for="cancel_reason">Cancellation Reason:</label>
<input class="data_cell" id="cancel_reason" type="text" name="cancel_reason" value="<?php echo $user['cancel_reason']; ?>" placeholder="Cancelled Reason"/>
</td>
<td>
<!-- Was Save Appointment Setup -->
<label class="label" for="save_setup">Was Save Setup:</label>
<select class="data_cell" id="save_setup" type="text" name="save_setup">
	<option>Choose if applies</option>
	<option>Not Set-Up</option>
	<option>Yes, see date</option>
</select>
</td>
</tr>
<tr>
<td>
<!-- Saved Appointment Date -->
<label class="label" for="save_setup_date">Save Setup Date:</label>
<input class="data_cell" id="save_setup_date" type="date" name="save_setup_date" value="<?php echo $user['save_setup_date']; ?>"/>
</td>
<td>
<!-- Was Sale Saved -->
<label class="label" for="saved">Was Sale Saved:</label>
<select class="data_cell" id="saved" type="text" name="saved">
	<option>Choose if applies</option>
	<option>Yes</option>
	<option>No</option>
</select>
</td>
<td>
<!-- New Sale Date -->
<label class="label" for="new_sale_date">New Sale Date:</label>
<input class="data_cell" id="new_sale_date" type="date" name="new_sale_date" value="<?php echo $user['new_sale_date']; ?>"/>
</td>
</tr>
<tr>
<td>
<!-- New Sale Gross Amount -->
<label class="label" for="new_gross_sale">New Gross Sale Amount:</label>
<input class="data_cell" id="new_gross_sale" type="text" name="new_gross_sale" value="<?php echo $user['new_gross_sale']; ?>" placeholder="New Gross Sale Amount"/>
</td>
<td>
<!-- Was Finance Approved -->
<label class="label" for="new_finance-approved">New Finance Approved:</label>
<select class="data_cell" id="new_finance-approved" type="text" name="new_finance_approved">
	<option>Choose One</option>
	<option>Pending</option>
	<option>Approved</option>
	<option>Declined</option>
</select>
</td>
<td>
<!--  New Maximun Approved For -->
<label class="label" for="new_max_approved">New Max Amount Approved:</label>
<input class="data_cell" id="new_max_approved" type="text" name="new_max_approved" value="<?php echo $user['new_max_approved']; ?>" placeholder="max approved for"/>
</td>
</tr>
<tr>
<td>
<!-- New Finance Charges -->
<label class="label" for="new_finance_charges">New Finance Charges:</label>
<input class="data_cell" id="new_finance_charges" type="text" name="new_finance_charges" value="<?php echo $user['new_finance_charges']; ?>" placeholder="New Finance Charges"/>
</td>
<td>
<!-- New Other Charge Off Gross -->
<label class="label" for="new_other-charges">New Other Charges Off Gross:</label>
<input class="data_cell" id="ne_other_charges" type="text" name="new_other_charge_off_gross" value="<?php echo $user['new_other_charge_off_gross']; ?>" placeholder="New Other Charge Off Gross"/>
</td>
<td>
<!-- New Other Charges For -->
<label class="label" for="new_other_for">New Other Charges For:</label>
<input class="data_cell" id="new_other_for" type="text" name="new_other_charges_for" value="<?php echo $user['new_other_charges_for']; ?>" placeholder="New Other Charges For"/>
</td>
</tr>
<tr>
<td>
<!-- New PII Complete -->
<label class="label" for="new_pii">New PII Complete:</label>
<input class="data_cell" id="new_pii" type="text" name="new_pii_complete" value="<?php echo $user['new_pii_complete']; ?>" placeholder="New Other Charges For"/>
</td>
<td>
<!-- Saved Sale Split -->
<label class="label" for="new_split">Was Saved Sale Split:</label>
<select class="data_cell" id="new_split" type="text" name="saved_sale_split">
	<option>Sale Not Split</option>
	<option>Mark Herbst</option>
	<option>Larry Probst</option>
	<option>Ken Petranek</option>
	<option>Ralph Smith</option>
</select>
</td>
</tr>
</table>
</div>

<br/>
<h3>Status Net</h3>
<div id="status_net_section">
<table>
<tr>
<td>
<!-- Status Net -->
<label class="label" for="status_net">Status Net:</label>
<select class="data_cell" id="status_net" type="text" name="status_net">
	<option>Pending</option>
	<option>Yes</option>
	<option>No</option>
</select>
</td>
<td>
<!-- Targeted Net Date-->
<label class="label" for="targeted_net_date">Targeted Net Date:</label>
<input class="data_cell" id="targeted_net_date" type="date" name="targeted_net_date" value="<?php echo $user['targeted_net_date']; ?>"/>
</td>
<td>
<!-- Sale Hold Up Reason-->
<label class="label" for="hold_up">Hold Up Reason:</label>
<input class="data_cell" id="hold_up" type="text" name="other_holdup_reason" value="<?php echo $user['other_holdup_reason']; ?>" placeholder="Is sale held up? Why?"/>
</td>
</tr>
<tr>
<td>
<!-- Hold Up Plan-->
<label class="label" for="hold_up_plan">Hold Up Plan:</label>
<input class="data_cell" id="hold_up_plan" type="text" name="holdup_plan" value="<?php echo $user['holdup_plan']; ?>" placeholder="Is sale held up? Why?"/>
</td>
<td>
<!-- Adjusted Net After Fees-->
<label class="label" for="adjusted_after_fees">Adjusted Net After Fees:</label>
<input class="data_cell" id="adjusted_after_fees" type="text" name="adjusted_net_after_fees" value="<?php echo $user['adjusted_net_after_fees']; ?>" placeholder="Adjusted Net After Fees"/>
</td>
</tr>
<tr>
<td>
<!-- Above Rep Cost Commission-->
<label class="label" for="above_rep">Above Rep Cost Commission:</label>
<input class="data_cell" id="above_rep" type="text" name="above_rep_cost_comm" value="<?php echo $user['above_rep_cost_comm']; ?>" placeholder="Above Rep Cost Commission"/>
</td>
<td>
<!-- Max Possible NSLI-->
<label class="label" for="max_nsli">Max Possible NSLI:</label>
<input class="data_cell" id="max_nsli" type="text" name="max_possible_nsli" value="<?php echo $user['max_possible_nsli']; ?>" placeholder="Above Rep Cost Commission"/>
</td>
</tr>
</table>
</div>

<br/><br/>
<h3>Net Revoked</h3>
<div id="net_revoked_section">
<table>
<tr>
<td>
<!-- Net Revoked -->
<label class="label" for="net-revoked">Net Revoked:</label>
<select id="net_revoked" class="data_cell" type="text" name="net_revoked">
	<option>Does Not Apply</option>
	<option>Yes</option>
	<option>No</ooption>
</select>
</td>
<td>
<!-- Reason Revoked-->
<label class="label" for="reason-revoked">Reason Revoked:</label>
<input id="reason_revoked" class="data_cell" type="text" name="reason_revoked" value="<?php echo $user['reason_revoked']; ?>" placeholder="Reason Revoked"/>
</td>
<td>
<!-- Back Charge YES/NO -->
<label class="label" for="back_charge">Back Charge:</label>
<select id="back_charge" class="data_cell" type="text" name="back_charge">
	<option>Does Not Apply</option>
	<option>Yes</option>
	<option>No</option>
</select>
</td>
</tr>
<tr>
<td>
<!-- Amount of Back Charge-->
<label class="label" for="how_much">Back Charge Amount:</label>
<input id="how_much" class="data_cell" type="text" name="how_much" value="<?php echo $user['how_much']; ?>" placeholder="Amount of Back Charge"/>
</td>
<td>
<!-- Reason for Back Charge-->
<label class="label" for="back_charge_reason">Back Charge Reason:</label>
<input id="back_charge_reason" class="data_cell" type="text" name="back_charge_reason" value="<?php echo $user['back_charge_reason']; ?>" placeholder="Reason for Back Charge"/>
</td>
</tr>
</table>
</div>

<br/>
<h3>Ordered/Installed</h3>
<div id="ordered_section">
<table>
<tr>
<td>
<!--Was Product Ordered -->
<label class="label" for="ordered">Was Product Ordered:</label>
<select id="ordered" class="data_cell" type="text" name="ordered">
	<option>Not Ordered</option>
	<option>Yes</option>
</select>
</td>
<td>
<!-- Projected Install Date-->
<label class="label" for="projected_install_date">Projected Install Date:</label>
<input id="projected_install_date" class="data_cell" type="date" name="projected_install_date" value="<?php echo $user['projected_install_date']; ?>" placeholder="Projected Install Date"/>
</td>
<td>
<!--Ready For install -->
<label class="label" for="ready_for_install">Ready For Install:</label>
<select id="ready_for_install" class="data_cell" type="text" name="ready_for_install">
	<option>No</option>
	<option>Yes</option>
</select>
</td>
</tr>
<tr>
<td>
<!--Installed -->
<label class="label" for="installed">Installed:</label>
<select id="installed" class="data_cell" type="text" name="installed">
	<option>No</option>
	<option>Yes</option>
</select>
</td>
<td>
<!--Ready to Pay Standard Commission -->
<label class="label" for="ready_comm">Ready to Pay Commission:</label>
<select id="ready_comm" class="data_cell" type="text" name="ready_comm">
	<option>No</option>
	<option>Yes</option>
</select>
</td>
</tr>
</table>
</div>

<br/>
<h3>Commission</h3>
<div id="comm_section">
<table>
<tr>
<td>
<!--Total Up Rep Commission-->
<label class="label" for="total_up">Total Up Rep Commission:</label>
<input id="total-up" class="data_cell" type="text" name="total_up_rep" value="<?php echo $user['total_up_rep']; ?>" placeholder="Total Up Rep Commission less possible NSLI"/>
</td>
<td>
<!--First Commission-->
<label class="label" for="first_comm">First Commission Paid:</label>
<input id="first_comm" class="data_cell" type="text" name="first_comm" value="<?php echo $user['first_comm']; ?>" placeholder="First Commission Paid"/>
</td>
<td>
<!--Second Commission-->
<label class="label" for="second_comm">Second Commission Paid:</label>
<input id="second_comm" class="data_cell" type="text" name="second_comm" value="<?php echo $user['second_comm']; ?>" placeholder="Second Commission"/>
</td>
</tr>
<tr>
<td>
<!--Balance of Commission-->
<label class="label" for="comm_balance">Commission Balance:</label>
<input id="comm_balance" class="data_cell" type="text" name="comm_balance" value="<?php echo $user['comm_balance']; ?>" placeholder="Commission Balance"/>
</td>
</tr>
</table>
</div>


<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>"/>

</form>
</div>
</body>

<!-- Udate Sale Action -->
<?php
if(isset($_POST['submit'])) {
	$u = "UPDATE sales SET
	 `level`='$_POST[level]',
	 `rep`='$_POST[rep]',
	 `cname`='$_POST[cname]',
	 `city`='$_POST[city]', 
	 `state`='$_POST[state]',
	 `gross_sale`='$_POST[gross_sale]',
	 `date_sold`='$_POST[date_sold]',
	 `deposit`='$_POST[deposit]',
	 `comments`='$_POST[comments]',
	 `sale_split`='$_POST[sale_split]',
	 `finance_approved`='$_POST[finance_approved]',
	 `max_approved`='$_POST[max_approved]',
	 `finance_charges`='$_POST[finance_charges]',
	 `other_rep_charge_off_gross`='$_POST[other_rep_charge_off_gross]',
	 `charge_off_for`='$_POST[charge_off_for]',
	 `adjusted_sale_amount`='$_POST[adjusted_sale_amount]',
	 `standard_financing`='$_POST[standard_financing]',
	 `finance_company_list_1`='$_POST[finance_company_list_1]',
	 `finance_company_list_2`='$_POST[finance_company_list_2]',
	 `pii`='$_POST[pii]',
	 `cancelled`='$_POST[cancelled]',
	 `cancel_reason`='$_POST[cancel_reason]',
	 `save_setup`='$_POST[save_setup]',
	 `save_setup_date`='$_POST[save_setup_date]',
	 `saved`='$_POST[saved]',
	 `new_sale_date`='$_POST[new_sale_date]',
	 `new_gross_sale`='$_POST[new_gross_sale]',
	 `new_finance_approved`='$_POST[new_finance_approved]',
	 `new_max_approved`='$_POST[new_max_approved]',
	 `new_finance_charges`='$_POST[new_finance_charges]',
	 `new_other_charge_off_gross`='$_POST[new_other_charge_off_gross]',
	 `new_other_charges_for`='$_POST[new_other_charges_for]',
	 `new_pii_complete`='$_POST[new_pii_complete]',
	 `saved_sale_split`='$_POST[saved_sale_split]',
	 `status_net`='$_POST[status_net]',
	 `targeted_net_date`='$_POST[targeted_net_date]',
	 `other_holdup_reason`='$_POST[other_holdup_reason]',
	 `holdup_plan`='$_POST[holdup_plan]',
	 `adjusted_net_after_fees`='$_POST[adjusted_net_after_fees]',
	 `above_rep_cost_comm`='$_POST[above_rep_cost_comm]',
	 `max_possible_nsli`='$_POST[max_possible_nsli]',
	 `net_revoked`='$_POST[net_revoked]',
	 `reason_revoked`='$_POST[reason_revoked]',
	 `back_charge`='$_POST[back_charge]',
	 `how_much`='$_POST[how_much]',
	 `back_charge_reason`='$_POST[back_charge_reason]',
	 `ordered`='$_POST[ordered]',
	 `projected_install_date`='$_POST[projected_install_date]',
	 `ready_for_install`='$_POST[ready_for_install]',
	 `installed`='$_POST[installed]',
	 `ready_comm`='$_POST[ready_comm]',
	 `total_up_rep`='$_POST[total_up_rep]',
	 `first_comm`='$_POST[first_comm]',
	 `second_comm`='$_POST[second_comm]',
	 `comm_balance`='$_POST[comm_balance]'
	 WHERE `id` = $_POST[id]";
	mysql_query($u) or die(mysql_error());
	
	echo "You Have Modified This Sale. Click Here $link";
}
?>

Re: Need true php mysql pro

Posted: Thu Mar 06, 2014 5:16 pm
by Celauran

Code: Select all

if(!isset($_POST['submit'])) {

$q = "SELECT * FROM sales WHERE id = $_GET[id]";
You're looking for a GET parameter to populate the form initially, not adding that same parameter to your form's action, and not using any POST values to re-populate the form. Either option is fine, really. The former keeps URLs consistent.