ncncnc Posted March 29, 2012 Share Posted March 29, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/259935-sql-php-update-records-query/ Share on other sites More sharing options...
Muddy_Funster Posted March 29, 2012 Share Posted March 29, 2012 you either pull information out of your database, or push information in, you can't do both at the same time. There is nothing wrong with the way you are doing it. Quote Link to comment https://forums.phpfreaks.com/topic/259935-sql-php-update-records-query/#findComment-1332283 Share on other sites More sharing options...
ncncnc Posted March 29, 2012 Author Share Posted March 29, 2012 In that case I don't know what the problem is because I'm getting no error messages. Quote Link to comment https://forums.phpfreaks.com/topic/259935-sql-php-update-records-query/#findComment-1332287 Share on other sites More sharing options...
Muddy_Funster Posted March 29, 2012 Share Posted March 29, 2012 In that case I don't know what the problem is because I'm getting no error messages. well neither do I, as you didn't actualy say you were having one. Could you describe the problem in detail? Quote Link to comment https://forums.phpfreaks.com/topic/259935-sql-php-update-records-query/#findComment-1332292 Share on other sites More sharing options...
ncncnc Posted March 29, 2012 Author Share Posted March 29, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/259935-sql-php-update-records-query/#findComment-1332299 Share on other sites More sharing options...
Muddy_Funster Posted March 29, 2012 Share Posted March 29, 2012 well you never actualy execute the $editQuery statement.... Quote Link to comment https://forums.phpfreaks.com/topic/259935-sql-php-update-records-query/#findComment-1332300 Share on other sites More sharing options...
ncncnc Posted March 29, 2012 Author Share Posted March 29, 2012 Of course. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/259935-sql-php-update-records-query/#findComment-1332303 Share on other sites More sharing options...
Muddy_Funster Posted March 29, 2012 Share Posted March 29, 2012 no problem, good luck Quote Link to comment https://forums.phpfreaks.com/topic/259935-sql-php-update-records-query/#findComment-1332307 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.