Jump to content

SQL PHP Update records query...


ncncnc

Recommended Posts

Hi all,

 

I'm trying to make a query that allows the user to edit the name of a entry in SQL. I believe I have the corect Syntax but I'm not sure if I have the code set up correctly. I am using 2 queries when I think it is possible with one. The first query is used to Pint out results for a certain year and the second to update the names.

 

 $desiredYear = $_POST['year'];
$nameEdit = $_POST['edit'];
$origName = $_POST['orig'];

echo ' The year you have chosen is '.$desiredYear;

$describeQuery = "SELECT ID, Name, (SELECT SUM(SalesVolume) as SalesVolume FROM MonthlySales WHERE ProductCode=Products.ID AND Year = '$desiredYear') AS num_sales FROM Products";
$editQuery = "UPDATE Products SET Name = '$nameEdit'  WHERE Name ='$origName'";


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

echo '<table border="1" BORDERCOLOR=Black>';
echo '<tr><th bgcolor = "LightBlue">Name</th><th bgcolor = "LightBlue" >ID</th> <th bgcolor = "LightBlue" >Sales</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['num_sales'].'</td>'; 

echo '</tr>';
} 

echo '</table>';
sqlsrv_close($conn);


 

Can somebody help me with this?

 

Thank you

Link to comment
Share on other sites

What I'm trying to do is make a webpage that dyanically updates the name of a product which is displayed in a table.

 

The user enters the name of an existing product into a form, then enters what they want the name to be changed to. I want the table to update and show the new updated data.

 

My current code just prints out the product list and doesn't change the name after the user has filled in the form. 

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.