Jump to content

Refreshing After Posts


anonymousmofo

Recommended Posts

I have made a website that deals with the sales of different products. It handles the total sales of a specific product. One of the aspects of the website is that it can change the current sales data of the products.

 

At the moment I can change the sales figures fine however I have to click the submit button once and then physically refresh the page for it to change the data in the table.

 

Is there a way that I can automatically refresh the page once the submit button is pressed?

 

I have tried using headers for example:


if (!empty($_POST['NSales']))
{
header('location: currentpage.php');
}

 

 

 

however this just constantly refreshes the page.

 

Any help would be greatly appreciated

Link to comment
Share on other sites

It sounds like your code responsible for getting and displaying the data is executed first. The logic on your page needs to be organized with the main php code that operates on submitted data first, followed by any code that produces the content to be displayed on the the page. The general flow in any code should be - inputs, processing, output.

 

In any case, we cannot directly help without seeing the code that reproduces the symptom (I can think of 2-3 reasons other then the organization of the logic on the page that could cause the same symptom.)

Link to comment
Share on other sites

Thanks for the quick reply, this is my code so far with the forms and querys.

 

<form name="input" action="Page4.php" method="post">
Year: <input type="text" name="year" />
Month: <input type="text" name="month" />
Product: <input type="text" name="pName" />

New Sales Volume: <input type="text" style="background-color:black;color: white;" 
name="NSales" />
<input type="submit" value="Submit" />
</form>

<?php 
error_reporting(E_ERROR | E_PARSE); 


$server = 'SQL2008';
$connectionInfo = array( "Database"=>"rde_400804");
$conn = sqlsrv_connect($server,$connectionInfo);

$desiredYear = $_POST['year'];
$desiredMonth = $_POST['month'];
$desiredProduct = $_POST['pName'];
$newSales = $_POST['NSales'];


$describeQuery = "SELECT p.ID, p.NAME, dt.[Year], dt.[Month], dt.SalesVolume from Products p
join
(select ProductCode, sum(SalesVolume) as SalesVolume, [Month], [Year] from MonthlySales 
where [Year] = '$desiredYear' AND [Month] = '$desiredMonth'
group by ProductCode, [Year], [Month])dt
on dt.ProductCode = p.ID";



$editQuery = "UPDATE MonthlySales SET SalesVolume = '$newSales'  WHERE  Year = '$desiredYear' AND Month = '$desiredMonth' AND ProductCode = '$desiredProduct' ";

$results = sqlsrv_query($conn, $describeQuery);
$resultsx = sqlsrv_query($conn, $editQuery);



echo '<table border="1" BORDERCOLOR=Black>';
echo '<tr><th bgcolor = "Black">Name</th><th bgcolor = "Black" >ID</th> <th bgcolor = "Black" >Sales</th><th bgcolor = "Black" >Month</th> <th bgcolor = "Black" >Year</th> </tr>';


while($row = sqlsrv_fetch_array($results,SQLSRV_FETCH_ASSOC)) 
  {   
  echo '<tr>';
echo '<td >' .$row['NAME'].'</td>';             
echo '<td>' .$row['ID'].'</td>'; 
echo '<td>' .$row['SalesVolume'].'</td>'; 
echo '<td>' .$row['Month'].'</td>'; 
echo '<td>' .$row['Year'].'</td>'; 
echo '</tr>';
} 

echo '</table>';




sqlsrv_close($conn);

Link to comment
Share on other sites

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.