anonymousmofo Posted April 11, 2012 Share Posted April 11, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/260745-refreshing-after-posts/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 11, 2012 Share Posted April 11, 2012 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.) Quote Link to comment https://forums.phpfreaks.com/topic/260745-refreshing-after-posts/#findComment-1336387 Share on other sites More sharing options...
anonymousmofo Posted April 11, 2012 Author Share Posted April 11, 2012 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); Quote Link to comment https://forums.phpfreaks.com/topic/260745-refreshing-after-posts/#findComment-1336390 Share on other sites More sharing options...
Muddy_Funster Posted April 11, 2012 Share Posted April 11, 2012 swap these two lines about $results = sqlsrv_query($conn, $describeQuery); $resultsx = sqlsrv_query($conn, $editQuery); Your pulling the info before you update it Quote Link to comment https://forums.phpfreaks.com/topic/260745-refreshing-after-posts/#findComment-1336391 Share on other sites More sharing options...
anonymousmofo Posted April 11, 2012 Author Share Posted April 11, 2012 Thank you Muddy_Funster, mission accomplished Quote Link to comment https://forums.phpfreaks.com/topic/260745-refreshing-after-posts/#findComment-1336394 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.