Jump to content

anonymousmofo

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Everything posted by anonymousmofo

  1. Thank you Muddy_Funster, mission accomplished
  2. Thanks for the quick reply, this is my code so far with the forms and querys. <form name="input" action="Page4.php" method="post"> Year: <input type="text" name="year" /> Month: <input type="text" name="month" /> Product: <input type="text" name="pName" /> New Sales Volume: <input type="text" style="background-color:black;color: white;" name="NSales" /> <input type="submit" value="Submit" /> </form> <?php error_reporting(E_ERROR | E_PARSE); $server = 'SQL2008'; $connectionInfo = array( "Database"=>"rde_400804"); $conn = sqlsrv_connect($server,$connectionInfo); $desiredYear = $_POST['year']; $desiredMonth = $_POST['month']; $desiredProduct = $_POST['pName']; $newSales = $_POST['NSales']; $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 Year = '$desiredYear' AND Month = '$desiredMonth' AND ProductCode = '$desiredProduct' "; $results = sqlsrv_query($conn, $describeQuery); $resultsx = sqlsrv_query($conn, $editQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "Black">Name</th><th bgcolor = "Black" >ID</th> <th bgcolor = "Black" >Sales</th><th bgcolor = "Black" >Month</th> <th bgcolor = "Black" >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>'; sqlsrv_close($conn);
  3. I have made a website that deals with the sales of different products. It handles the total sales of a specific product. One of the aspects of the website is that it can change the current sales data of the products. At the moment I can change the sales figures fine however I have to click the submit button once and then physically refresh the page for it to change the data in the table. Is there a way that I can automatically refresh the page once the submit button is pressed? I have tried using headers for example: if (!empty($_POST['NSales'])) { header('location: currentpage.php'); } however this just constantly refreshes the page. Any help would be greatly appreciated
  4. I implemented your code into my website and when I run it it displays 'Query error: Array'. Thoughts?
  5. I have taken the qoutes out of the code and it still gives me the same error message $describeQuery = "SELECT (Cars.Price * SUM(MonthlySales.TotalSales)) as revenue FROM Car INNER JOIN MonthlySales ON(Cars.CarCode = MonthlySales.ProductCode)GROUP BY Cars.CarCode"; $query = sqlsrv_query( $link, $describeQuery); echo '<table border = "2" bordercolor = "Black">'; echo '<tr><th bgcolor = "Black">Revenue</th></tr>'; while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td>' . $row['revenue'] . '</td>'; echo '</tr>'; } echo '</table>'; if(sqlsrv_errors() !== null) { print_r(sqlsrv_errors()); } sqlsrv_close($link); ?> </font> </body> </html>
  6. $describeQuery = "SELECT (Cars.Price * SUM(MonthlySales.TotalSales)) as revenue FROM Cars INNER JOIN MonthlySales ON(Cars.'CarCode' = MonthlySales.'ProductCode')GROUP BY Cars.'Car'"; $query = sqlsrv_query( $link, $describeQuery); echo '<table border = "2" bordercolor = "Black">'; echo '<tr><th bgcolor = "Black">Revenue</th><tr>'; while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td>' . $row['revenue'] . '</td>'; echo '</tr>'; } echo '</table>'; if(sqlsrv_errors() !== null) { print_r(sqlsrv_errors()); } sqlsrv_close($link); ?> </font> </body> </html>
  7. Have just tried your SUM code and that you posted however still no joy. I am getting the same error as before, an invalid parameter was passed. Could this be because i am missing some single quotes off one of the column headings? I think it will be something simple
  8. My exact table names are as follows: Cars CarCode,Model, Price MonthlySales ID, ProductCode, Month, Year, TotalSales CarCode and ProductCode are the same thing but in two different tables.
  9. I have tried your code which you suggested however it is coming up with an error message: Array ( [0] => Array ( [0] => IMSSP [sqlSTATE] => IMSSP [1] => -14=> -14 [2] => An invalid parameter was passed to sqlsrv_fetch_array. [message] => An invalid parameter was passed to sqlsrv_fetch_array. ) ) I have checked all of the column names and they match up fine with the ones i am using. any thoughts?
  10. I am currently building a website which deals with sales of cars. I need to be able to work out the total revenue of the cars by calculating the total sales * price. However the problem i am having is the Price and total sales are in 2 different tables. The First Table: Cars Table: Car Code, Make, Model, Price The second Table: Sales Table: Car ID, Month, Year, Total Sales (Car Code and Car ID are linked together with a relationship) How can i get the price of one car and multiply it with the total sales figure to get the revenue? Any help would be much Appreciated.
  11. I can see what you mean however i am back to square one, The table is now shown however there are duplicate records. When i could not see the table before and i had this code: $describeQuery="select name, Id, Price from Products"; $results = sqlsrv_query($conn, $describeQuery); in the if statement as you originally suggested it seemed to be working fine. When i checked the table it only had one of each entry which is what i want it to have.
  12. Right that seems now to be working however it will not now print out the table on the web page would i have to change anything where the table is drawn? Here is the code: if (!empty($_POST)) { $insert_query = "INSERT INTO Cars (Make,Model,Price) VALUES (?,?,?)"; $Make = $_POST['Make']; $Model = $_POST['Model']; $Price = $_POST['Price']; $params = array("$Make","$Model", "$Price" ); $result = sqlsrv_query($conn,$insert_query,$params); $describeQuery="select Make, Model, Price from Cars"; $results = sqlsrv_query($conn, $describeQuery); header('location: NewCar.php'); } echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Make</th><th bgcolor = "LightBlue">Model</th><th bgcolor = "LightBlue">Price</th></tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['Make'].'</td>'; echo '<td >' .$row['Model'].'</td>'; echo '<td >£' .$row['Price'].'</td>'; echo '</tr>'; } echo '</table>';
  13. Yes this will solve the problem of entering empty rows however there is still the problem of entering a car and that being entered twice into the table. Eg. when i enter 'ferrari' into the table 'ferrari' is added again when the page is refreshed
  14. <form name="input" action="NewProduct.php" method="post"> ID: <input type="text" name="ID" /> Product: <input type="text" name="Product" /> Price: <input type="text" name="Price" /> <input type="submit" value="Submit" /> </form> <?php $server = '********'; $connectionInfo = array( "Database"=>"********"); $conn = sqlsrv_connect($server,$connectionInfo); $insert_query = "INSERT INTO Car (Make,Model,Price) VALUES (?,?,?)"; $Make = $_POST['Make']; $Model = $_POST['Model']; $Price = $_POST['Price']; $params = array("$Make","$Model", "$Price" ); $result = sqlsrv_query($conn,$insert_query,$params); $describeQuery="select Make,Model,Price from Cars"; $results = sqlsrv_query($conn, $describeQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Make</th><th bgcolor = "LightBlue">Model</th><th bgcolor = "LightBlue">Price</th></tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['Make'].'</td>'; echo '<td >' .$row['Model'].'</td>'; echo '<td >£' .$row['Price'].'</td>'; echo '</tr>'; } echo '</table>'; sqlsrv_close($conn); This is suppose to let me enter new cars into a table however when i refresh this page it keeps re entering the previously entered car.
  15. I have used the header and have redirected it to the same page however it is still inserting it twice into my table. Any Further ideas?
  16. I am currently building a website which uses postbacks. How can I clear the postback so that it can only be posted once because at the minute when i refresh the page it keeps adding the same entry. Any help would be appreciated
×
×
  • 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.