Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2012
    Posts
    7

    Unanswered: Edit / Updates Query

    Hi Guys,

    I am currently working on a website that deals with sales of products. For one of my pages for the website I need it to be able to change the current sales information for a specific product.

    The top part of the following code selects the specific product however I cannot get the update query to work.

    Can anybody help please?

    Thank you

    Code:
    $describeQuery = "SELECT p.ID, p.NAME, dt.[Year], dt.[Month], dt.SalesVolume FROM Products p
    						join
    						(select ProductCode, sum(SalesVolume) as SalesVolume, [Year], [Month] from MonthlySales 						
    						group by ProductCode, [Year], [Month])dt
    						on dt.ProductCode = p.ID WHERE [NAME] = '$desiredProduct' AND [Year] = '$desiredYear' AND [Month] = '$desiredMonth'";
    
    
    
    	$editQuery = "UPDATE MonthlySales SET SalesVolume = '$NewSales' WHERE ID = '$desiredProduct' AND Year = '$desiredYear' AND Month = '$desiredMonth'";
    
    
    	$query = sqlsrv_query($link, $describeQuery);

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i think you actually have to execute $editQuery
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2012
    Posts
    7
    Yes I have executed the query It apparently didnt copy properly :/ Here is The full code.

    Code:
    $describeQuery = "SELECT p.ID, p.NAME, dt.[Year], dt.[Month], dt.SalesVolume FROM Products p
    						join
    						(select ProductCode, sum(SalesVolume) as SalesVolume, [Year], [Month] from MonthlySales 						
    						group by ProductCode, [Year], [Month])dt
    						on dt.ProductCode = p.ID WHERE [NAME] = '$desiredProduct' AND [Year] = '$desiredYear' AND [Month] = '$desiredMonth'";
    
    
    
    	$editQuery = "UPDATE MonthlySales SET SalesVolume = '$NewSales' WHERE [NAME] = '$desiredProduct'";
    
    
    
    	$query = sqlsrv_query($link, $describeQuery);			
    	$resultsx = sqlsrv_query($conn, $editQuery);

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    "I cannot get the update query to work" is not a recognized error message

    please explain what happened when you executed it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •