ncncnc Posted April 11, 2012 Share Posted April 11, 2012 Hi all, I'm trying to make a webpage that allows the user to enter new sales figures for a certain product in a chosen month of a chosen year. I thought my code was correct but it doesn't really do anything. It just displays the table but it's not updated. Can anybody spot an error? $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 Month ='$desiredMonth' AND Name = '$desiredProduct' AND Year = '$desiredYear'"; $results = sqlsrv_query($conn, $describeQuery); $resultsx = sqlsrv_query($conn, $editQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Name</th><th bgcolor = "LightBlue" >ID</th> <th bgcolor = "LightBlue" >Sales</th><th bgcolor = "LightBlue" >Month</th> <th bgcolor = "LightBlue" >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>'; while($row = sqlsrv_fetch_array($resultsx, SQLSRV_FETCH_ASSOC)) { } sqlsrv_close($conn); Link to comment https://forums.phpfreaks.com/topic/260726-editing-monthly-sales-figures/ Share on other sites More sharing options...
MMDE Posted April 11, 2012 Share Posted April 11, 2012 Maybe if we try reading what the script does, and you can tell me if this is really what you want it to do... You want it to first get the old data from the database, and then update the database with new data? Link to comment https://forums.phpfreaks.com/topic/260726-editing-monthly-sales-figures/#findComment-1336306 Share on other sites More sharing options...
ncncnc Posted April 11, 2012 Author Share Posted April 11, 2012 I want it to update the databse with the new data the user has inputted from the form. Link to comment https://forums.phpfreaks.com/topic/260726-editing-monthly-sales-figures/#findComment-1336310 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.