Jump to content

Editing monthly sales figures..


ncncnc

Recommended Posts

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
Share on other sites

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
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.