Jump to content

bambinou1980

Members
  • Posts

    130
  • Joined

  • Last visited

Everything posted by bambinou1980

  1. Thanks Psycho for your help. Here is what I was trying to achieve: This is for a little factory that may or may not have resellers when creating an order. Imagine a form where there are 2 dropdown menus at the top, one to choose the buyers(customer) and if any, one to choose a reseller. When the reseller is chosen and the operator has added the quantity required to the order, a jquery code does all the calculations and creates a total for the order itself with an order id and a total of commission for the reseller. The reason I added the earnings of the reseller inside the order table was because I wanted to have a static proof of the order, this way if anyone changes the reseller details, or delete the user or change it's commission percentage, I was hoping to have an order that cannot be modified in any way, this is why I kept both tables separated. As I had a script a few years back made by a dev for a little company and when the reseller was changing his details, all the invoicing details were affected(even the old invoices). Now based on that order table, because there are reseller user ids, I was hoping to do all the calculations from there by simply pull up all the reseller ids(if any as we may not have a reseller per order), then group their totals together and only show in the view table the resellers that have gained a commission and not the others who have not earned anything. So really all I wanted to group when the "list monthly payment to resellers" page showed up was: 2 date pickers and a table with: reseller id Reseller name Reseller surname Reseller earnings Reseller email Reseller phone number Reseller V.A.T number Now at the end of the row, I would like to add a button that you press when the payment is done in the accoutning software, upon pressing the button, this particular reseller payment will be set as "paid", so here I also have a missing column which I believe I will include in the "order" table aswell(if I am correct). Regarding the sql code you gave me, I am getting this error: Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\xampp\htdocs\food\admin\crud\resellers\list-payments.php on line 165 Any idea what this might me? Should the date not be showing as: WHERE orders.due_date >= CAST('2014-01-01' AS date) AND orders.due_date <= CAST('2016-08-21' AS date) When I put my old code, I get some results but of course the sum: $sql = "SELECT DISTINCT orders.resellers_id, resellers.reseller_name, resellers.reseller_surname, orders.reseller_earnings, orders.reseller_commission, resellers.reseller_email, resellers.reseller_phone FROM orders INNER JOIN resellers ON orders.resellers_id = resellers.id WHERE orders.due_date >= CAST('2014-01-01' AS date) AND orders.due_date <= CAST('2016-08-21' AS date) GROUP BY resellers.id ORDER BY orders.due_date"; Thank you for your work.
  2. Hi Barand, Yes sorry you are right. What I am trying to achieve is this: I have a table where I would like to show the reseller information as: id Name Surname Commission Email Phone Earnings In the order, of the above table headers, here are the rows: resellers_id || reseller_name || Reseller_surname || reseller_commission || reseller_email || reseller_phone || reseller_earnings Also, in that table I owuld like to add all the SUM of the reseller_earnings per resellers_id Finally I would like to choose a date range based on "due_date" of the orders table. Thank you so much as usual Barand! Ben
  3. Hello, I have a mistake in my query but cannot work out where: ...Any idea where my mistake is please? I am not trying to list in a table all the resellers commissions by adding together reseller ids(GROUP BY id but SUM resellers_earnings and by date range. SELECT o.id, o.reseller_earnings, o.order_status, r.reseller_name, r.reseller_surname, r.reseller_email, r.reseller_phone, r.reseller_commission, r.reseller_vat_number, r.resellers_id SUM(o.reseller_earnings) as total FROM orders as o, resellers as r WHERE o.resellers_id = r.id AND WHERE due_date BETWEEN '2014-08-14' AND '2015-08-14' AND o.order_status LIKE '%Order Completed%' GROUP BY resellers_id ORDER BY total DESC"; My sql gives me: Error SQL query: Documentation SELECT o.id, o.reseller_earnings, o.order_status, r.reseller_name, r.reseller_surname, r.reseller_email, r.reseller_phone, r.reseller_commission, r.reseller_vat_number, r.resellers_id SUM(o.reseller_earnings) as total FROM orders as o, resellers as r WHERE o.resellers_id = r.id AND WHERE due_date BETWEEN '2014-08-14' AND '2015-08-14' AND o.order_status LIKE '%Order Completed%' GROUP BY resellers_id ORDER BY total DESC"; GROUP BY resellers_id ORDER BY total DESC" LIMIT 0, 25 MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SUM(o.reseller_earnings) as total FROM orders as o, resellers as r W' at line 11
  4. Ah, I did not think about this one....now I am a little stuck with a new problem. As you can see in my first post I already have a while loop using $query as: $sql = "SELECT id, cust_order_id, cust_company, due_date, product, quantity, price, requirements, cust_order_total, order_status, resellers_id FROM orders ORDER BY id DESC $limit"; $query = mysqli_query($connection, $sql); I my while loop I am trying to output in my table all that data: <?php // Attempt select query execution if($result = mysqli_query($connection, $sql)){ if(mysqli_num_rows($result) > 0){ echo "<table class='table table-striped'>"; echo "<tr>"; echo "<th class='col-md-1 text-center'>id</th>"; echo "<th class='col-md-1 text-center'>Order ID</th>"; echo "<th class='col-md-1 text-center'>Company</th>"; echo "<th class='col-md-1 text-center'>Due Date</th>"; echo "<th class='col-md-1 text-center'>Product</th>"; echo "<th class='col-md-1 text-center'>Unit Price</th>"; echo "<th class='col-md-1 text-center'>Quantity</th>"; echo "<th class='col-md-1 text-center'>Order Total</th>"; echo "<th class='col-md-5 text-center'>Requirements</th>"; echo "<th class='col-md-1 text-center'>Reseller</th>"; echo "<th class='col-md-1 text-center'>Order Status</th>"; echo "<th class='col-md-1 text-center'></th>"; while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ $id = htmlspecialchars($row["id"]); $cust_order_id = $row["cust_order_id"]; $cust_company = $row["cust_company"]; $due_date = $row["due_date"]; $product = $row["product"]; $quantity = $row["quantity"]; $price = $row["price"]; $requirements = $row["requirements"]; $cust_order_total = $row["cust_order_total"]; $resellers = $row["resellers_id"]; $order_status = $row["order_status"]; echo "<tr class='text-center'>"; echo "<td>" . htmlspecialchars($id) . "</td>"; echo "<td>" . htmlspecialchars($cust_order_id) . "</td>"; echo "<td>" . htmlspecialchars($cust_company) . "</td>"; $new_date = date("d-m-Y", strtotime($due_date)); echo "<td>" . $new_date . "</td>"; echo "<td>" . htmlspecialchars($product) . "</td>"; echo "<td>" . htmlspecialchars($price) . "</td>"; echo "<td>" . htmlspecialchars($quantity) . "</td>"; echo "<td>" . htmlspecialchars($cust_order_total) . "</td>"; echo "<td>" . htmlspecialchars($requirements) . "</td>"; echo "<td>" . htmlspecialchars($resellers) . "</td>"; echo "<td>" . htmlspecialchars($order_status) . "</td>"; echo "<td><a class='btn btn-default' href='update-orders.php?order=$id' role='button'>Edit</a><a class='btn btn-danger' href='delete-orders.php?order=$id' onclick=\"return confirm('Are you sure you want to delete this order?');\" role='button'>Delete</a></td>"; echo "</tr>"; } echo "</table>"; // Close result set mysqli_free_result($result); }else{ echo "Not Results to Show, get more customers!!"; }} ?> But, in one of the colum of my table I need the results from the related table of the second query: $query2 = "SELECT `orders`.*, `resellers`.`reseller_name` FROM `orders` INNER JOIN `resellers` ON `orders`.`resellers_id` = `resellers`.`id` WHERE `orders`.`id` = '46'"; All I am trying to do is output the surname and name of the reseller "echo "<th class='col-md-1 text-center'>Reseller</th>";" in that column, but that data is from the $query2. How can I merge both queries into 1 and output the name and surname of that reseller table in that column please? "$resellers = $row["resellers_id"];" like this: while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ $id = htmlspecialchars($row["id"]); (Table `orders`) $cust_order_id = $row["cust_order_id"]; (Table `orders`) $cust_company = $row["cust_company"]; (Table `orders`) $due_date = $row["due_date"]; (Table `orders`) $product = $row["product"]; (Table `orders`) $quantity = $row["quantity"]; (Table `orders`) $price = $row["price"]; (Table `orders`) $requirements = $row["requirements"]; (Table `orders`) $cust_order_total = $row["cust_order_total"]; (Table `orders`) $resellers = $row["resellers_id"]; (Table `resellers`)I need to pull the name and surname of the resellers there $order_status = $row["order_status"]; (Table `orders`) I thought it was going to be easy after finding a working query but it is actually becoming more complicated...
  5. Thank ou so much, well spotted, I also had another error SELECT `orders`.*, `resellers`.`reseller_name` FROM `orders` INNER JOIN `resellers` ON `orders`.`resellers_id` = `resellers`.`id` WHERE `orders`.`id` = '46'; It was "reseller_name" and not "reseller". It is working! Thanks
  6. I also tried this but it is a fail too..it returns nothing....query is ok but nothing is returned at all. SELECT resellers_id, reseller_name, reseller_surname FROM orders T1 INNER JOIN resellers T2 ON T1.resellers_id = T2.reseller_name
  7. Oups sorry....ahahah Here it is: I tried this but the sql does not work..... SELECT 'orders'.*, 'resellers'.'name' FROM 'orders' INNER JOIN 'resellers' ON 'orders'.'resellers_id' = 'resellers'.'id' WHERE 'orders'.'id' = '46'; I am getting SELECT 'orders'.*, 'resellers'.'name' FROM 'orders' INNER JOIN 'resellers' ON 'orders'.'resellers_id' = 'resellers'.'id' WHERE 'orders'.'id' = 46 LIMIT 0, 25 MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.*, 'resellers'.'name' FROM 'orders' INNER JOIN 'resellers' ON 'orders'.'reselle' at line 1
  8. Hello, I am having a little problem. I have a listing table and would like to output the "name and surname" associated with the reseller id. I can currently output the reseller id, it is working fine but how to get his name from the associated table please(foreign key). Here is my query: <?php // Attempt select query execution if($result = mysqli_query($connection, $sql)){ if(mysqli_num_rows($result) > 0){ echo "<table class='table table-striped'>"; echo "<tr>"; echo "<th class='col-md-1 text-center'>id</th>"; echo "<th class='col-md-1 text-center'>Order ID</th>"; echo "<th class='col-md-1 text-center'>Company</th>"; echo "<th class='col-md-1 text-center'>Due Date</th>"; echo "<th class='col-md-1 text-center'>Product</th>"; echo "<th class='col-md-1 text-center'>Unit Price</th>"; echo "<th class='col-md-1 text-center'>Quantity</th>"; echo "<th class='col-md-1 text-center'>Order Total</th>"; echo "<th class='col-md-5 text-center'>Requirements</th>"; echo "<th class='col-md-1 text-center'>Reseller</th>"; echo "<th class='col-md-1 text-center'>Order Status</th>"; echo "<th class='col-md-1 text-center'></th>"; while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ $id = htmlspecialchars($row["id"]); $cust_order_id = $row["cust_order_id"]; $cust_company = $row["cust_company"]; $due_date = $row["due_date"]; $product = $row["product"]; $quantity = $row["quantity"]; $price = $row["price"]; $requirements = $row["requirements"]; $cust_order_total = $row["cust_order_total"]; $resellers = $row["resellers_id"]; $order_status = $row["order_status"]; echo "<tr class='text-center'>"; echo "<td>" . htmlspecialchars($id) . "</td>"; echo "<td>" . htmlspecialchars($cust_order_id) . "</td>"; echo "<td>" . htmlspecialchars($cust_company) . "</td>"; $new_date = date("d-m-Y", strtotime($due_date)); echo "<td>" . $new_date . "</td>"; echo "<td>" . htmlspecialchars($product) . "</td>"; echo "<td>" . htmlspecialchars($price) . "</td>"; echo "<td>" . htmlspecialchars($quantity) . "</td>"; echo "<td>" . htmlspecialchars($cust_order_total) . "</td>"; echo "<td>" . htmlspecialchars($requirements) . "</td>"; echo "<td>" . htmlspecialchars($resellers) . "</td>"; echo "<td>" . htmlspecialchars($order_status) . "</td>"; echo "<td><a class='btn btn-default' href='update-orders.php?order=$id' role='button'>Edit</a><a class='btn btn-danger' href='delete-orders.php?order=$id' onclick=\"return confirm('Are you sure you want to delete this order?');\" role='button'>Delete</a></td>"; echo "</tr>"; } echo "</table>"; // Close result set mysqli_free_result($result); }else{ echo "Not Results to Show, get more customers!!"; }} ?>
  9. Hi Barand, Thank you for the fast reply. I am not understanding why you add "MONTH(due_date) as month" does this function automatically recognise the /mm/ in the date itself? Thank you, Ben
  10. Hello, I have created the below query to get all the totals of sales during a chosen date from 3 date pickers. My question now is how to get 12 months of results when I choosen a year but have each months output it's total sales. The reaosn I need this is because I need to have an array showing every month + total sales per month so I can json_encode() it and pass it into a graph using Morris.js(Graph library) as shown here: <?php $query = "SELECT SUM(cust_order_total) AS order_total_sum FROM orders WHERE due_date BETWEEN '2015-08-14' AND '2015-10-14'"; $result = mysqli_query($connection, $query); while ($row = mysqli_fetch_array($result)){ echo $row['order_total_sum'];//This return totals of sales during chosen period. } ?> This currently output well the total sales during the chosen period, so it works. Now I need the exact same type of logic but When I click on the dropdown menu that choses a Year, I would like to see: Year 2014 Month 01 -> €239 02 -> €250 03 -> €456 And so on.... Any idea please? Remember I am saving the date as yyyy-mm-dd in mysql but read it as dd-mm-yyyy on the web page. Thank you, Ben
  11. Hello all, I would like to use the chart library called Morris.js, it seems quite pretty but I have a ltitle problem, stilll new to PHP..... I need a bit of help figuring this one out please, Morris.js seems to only read the data into jason format, I have always heard about json, took a little course tonight but I am still unsure on how to pull some data from mysql, transform it into an array, then from that array, encode it into json. My first question is, let's say I have a query and create an array from it(hope this is right..) $query = "SELECT * FROM id, sales, customer, months ORDER BY months; $months = array(); while(($row = mysqli_fetch_assoc($result))) { $months[] = $row['months']; $sales[] = $row['sales']; } Now that I have the array, how to I change it into json? It is my understanding that the generated json file will have to go into a folder and from there I will output the data from that folder into morris.js, am I correct? I am sorry but the morris.js explanations are a little bit complicated for me right now. Thanks! Ben
  12. Oh I see, ok got it, I thought there was something more behind it, no, those values will stay as it is(order processed or order not started or along those lines, only 2 choices.. Made great progress today with a lot of things, thanks to all! Coding was like Chinese to me 2 weeks ago , now I am understanding the logic behind, of course it is a huge world and I will perhaps never know how to code like you guys but the most important for me is to now be able to create solutions based on my junior level :-)) I really enjoy it! Sorry if I will ask a lot of different questions in the forum but each time I try a new thing, I need a bit of guidance or I might spend a lot of time trying to figure out something that is maybe super simple to you all. Thanks again! Ben
  13. Hi Barand, Do you mean the order_status? Why not having it in the order table itself? Would it not be easier? Thank you, Ben
  14. Hi Sccotash, could you please let me know why use auto increment in that table if I have only 2 values? Would it make a bit difference to go from 0 and 1 to 1 and 2? Thank you, Ben
  15. Hi The reason is because next year when I will upgrade the script I will put it online and have the boss controlling the access from home. I am left with one last problem, after this, everything will be fine as the hardest parts are not done. I have 2 tables: orders order_status When I have created my first insert, I have insert 0 in the orders row called orders_status_id. Now upon select, I would like to select this "0" so it output the corresponding 0 value in the order_status page which is "Not Done". How can I query the orders table in such way that it gives me the "Not Done" status please? I am watching daily php and mysql videos trying to understand the whole process but on this relational part, I am a bit lost still. Thank you, Ben
  16. Hello, I would like to add a bit of security to my script before sending the data to mysql using msqli. At the moment I have: $submit_product = mysqli_real_escape_string($connection, $submit_product); $submit_price = mysqli_real_escape_string($connection, $submit_price); But I am worried that the mysqli_real-escape_string is not right for the $submit_price" variable, what other laternative there are in PHP for decimal from $_POST? Thank you, Ben
  17. <form role="form" method="post" action="index.php"> <div class="form-group"><label for="order_id">Order ID</label><input type="text" name="cust_order_id" class="form-control" value="<?php echo "FP" .$random_number; ?>" readonly="readonly" /></div> <div class="form-group"><label for="name_id">Company *</label> <select name="cust_company" class="form-control" id="cust_company_id"> <?php $query_field1 = "SELECT * FROM customers ORDER BY cust_company desc"; $result_field1 = mysqli_query($connection, $query_field1) or die (mysqli_error()); while($row_field1 = mysqli_fetch_array($result_field1)){$cust_name = htmlspecialchars($row_field1['cust_name']);$cust_surname = htmlspecialchars($row_field1['cust_surname']);$cust_company = htmlspecialchars($row_field1['cust_company']); $cust_address = htmlspecialchars($row_field1['cust_address']); $cust_phone = htmlspecialchars($row_field1['cust_phone']); $cust_email = htmlspecialchars($row_field1['cust_email']); $cust_vat = htmlspecialchars($row_field1['cust_vat']);?> <option value="<?php echo $cust_company; ?>" data-name="<?php echo $cust_name; ?>" data-surname="<?php echo $cust_surname; ?>" data-address="<?php echo $cust_address; ?>" data-phone="<?php echo $cust_phone; ?>" data-email="<?php echo $cust_email; ?>" data-vat="<?php echo $cust_vat; ?>"><?php echo $cust_company; ?></option> <?php } ?> </select> </div> <div class="form-group"><label for="address_id">Address *</label><textarea name="cust_address" placeholder="Company's Address" rows="4" cols="50" class="form-control" readonly="readonly" ></textarea></div> <div class="form-group"><label for="name_id">Name *</label><input type="text" name="cust_name" placeholder="Customer Name" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="surname_id">Surname *</label><input type="text" name="cust_surname" placeholder="Customer Surname" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="phone_id">Phone</label><input type="text" name="cust_phone" placeholder="Customer Phone" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="email_id">Email</label><input type="email" name="cust_email" placeholder="Customer Email" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="vat_id">V.A.T Number(ie:MT20343324)</label><input type="text" name="cust_vat" placeholder="V.A.T Number" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="due_date_id">Due Date *</label><div class="form-inline well"> <div class="input-append date" id="dp3" data-date="12-02-2012" data-date-format="dd-mm-yyyy"> <input name="due_date" class="form-control" size="25" type="text" id="dp1" value="12-02-2012"> <span class="add-on"><i class="icon-th"></i></span></div> </div> </div> <script>$('#dp1').datepicker({ format: 'dd-mm-yyyy' });</script> <?php //Query all the prices $query_field2 = "SELECT * FROM products ORDER BY name desc"; $result_field2 = mysqli_query($connection, $query_field2) or die (mysqli_error());$choose_product_id = 0; $action_id = 0;$products_id = 0;$label_id = 0;$quantity = 0; while($row_field2 = mysqli_fetch_array($result_field2)){$name = htmlspecialchars($row_field2['name']);$price1 = htmlspecialchars($row_field2['price1']);$price2 = htmlspecialchars($row_field2['price2']);$price3 = htmlspecialchars($row_field2['price3']); ?><div class="form-inline well"><label for="<?php echo "label".++$label_id; ?>">Choose Product <?php echo ++$choose_product_id; ?></label><div class="form-group"> <!--Product name Select--><select name="<?php echo "action".++$action_id; ?>" class="form-control products" id="<?php echo "products".++$products_id; ?>"><?php $query_field3 = "SELECT * FROM products ORDER BY name desc"; $result_field3 = mysqli_query($connection, $query_field3) or die (mysqli_error()); while($row_field3 = mysqli_fetch_array($result_field3)){$product_name = htmlspecialchars($row_field3['name']);$product_price1 = htmlspecialchars($row_field3['price1']);$product_price2 = htmlspecialchars($row_field3['price2']); $product_price3 = htmlspecialchars($row_field3['price3']);?><option value="<?php echo $product_name; ?>" data-product_price1="<?php echo $product_price1; ?>" data-product_price2="<?php echo $product_price2; ?>" data-product_price3="<?php echo $product_price3; ?>"><?php echo $product_name; ?></option> <?php } ?> </select> <!--Price Select--> <select name="<?php echo "action".++$number2; ?>" class="form-control"> <option id="price1"></option><option id="price2"></option><option id="price3"></option> </select> <label for="product1_id">Qty</label><input name="<?php echo "quantity".++$quantity; ?>" type="text" class="form-control" maxlength="4" size="4" id="<?php echo "quantity".$quantity; ?>"> </div> </div> <?php } ?> <div class="form-inline well text-center"><button type="submit" name="submit" class="btn btn-success btn-lg">Create Order</button></div></div> </form> </div> </div></div></div></div><!--<script> $("#products").change(function() { $("#product_prices").load("getter.php?choice=" + $("#products").val());});</script> --><script> $('#cust_company_id').change(function() { selectedOption = $('option:selected', this); $('textarea[name=cust_address]').val( selectedOption.data('address') );$('input[name=cust_name]').val( selectedOption.data('name') );$('input[name=cust_surname]').val( selectedOption.data('surname') ); $('input[name=cust_phone]').val( selectedOption.data('phone') ); $('input[name=cust_email]').val( selectedOption.data('email') ); $('input[name=cust_vat]').val( selectedOption.data('vat') );}); </script> <script> $(".products").change(function() { selectedOption = $(this).find(":selected"); $(this).next().children().each(function(idx){ var num=idx+1; $(this).text( selectedOption.data('product_price'+num)); }); </script>
  18. Hi Mac_gyver, Yes now I am getting all the ids and all the php working right, where I am struggling is with the jquery. Here is my new code, remember I will then add this later on: http://jsfiddle.net/jaredwilli/tzpg4/4/ <form role="form" method="post" action="index.php"> <div class="form-group"> <label for="order_id"> Order ID </label> <input type="text" name="cust_order_id" class="form-control" value="<?php echo "FP" .$random_number; ?>" readonly="readonly" /> </div> <div class="form-group"> <label for="name_id"> Company * </label> <select name="cust_company" class="form-control" id="cust_company_id"> <?php $query_field1 = "SELECT * FROM customers ORDER BY cust_company desc"; $result_field1 = mysqli_query($connection, $query_field1) or die (mysqli_error()); while($row_field1 = mysqli_fetch_array($result_field1)){ $cust_name = htmlspecialchars($row_field1['cust_name']); $cust_surname = htmlspecialchars($row_field1['cust_surname']); $cust_company = htmlspecialchars($row_field1['cust_company']); $cust_address = htmlspecialchars($row_field1['cust_address']); $cust_phone = htmlspecialchars($row_field1['cust_phone']); $cust_email = htmlspecialchars($row_field1['cust_email']); $cust_vat = htmlspecialchars($row_field1['cust_vat']); ?> <option value="<?php echo $cust_company; ?>" data-name="<?php echo $cust_name; ?>" data-surname="<?php echo $cust_surname; ?>" data-address="<?php echo $cust_address; ?>" data-phone="<?php echo $cust_phone; ?>" data-email="<?php echo $cust_email; ?>" data-vat="<?php echo $cust_vat; ?>"><?php echo $cust_company; ?></option> <?php } ?> </select> </div> <div class="form-group"> <label for="address_id"> Address * </label> <textarea name="cust_address" placeholder="Company's Address" rows="4" cols="50" class="form-control" readonly="readonly" ></textarea> </div> <div class="form-group"> <label for="name_id"> Name * </label> <input type="text" name="cust_name" placeholder="Customer Name" class="form-control" value="" readonly="readonly" /> </div> <div class="form-group"> <label for="surname_id"> Surname * </label> <input type="text" name="cust_surname" placeholder="Customer Surname" class="form-control" value="" readonly="readonly" /> </div> <div class="form-group"> <label for="phone_id"> Phone </label> <input type="text" name="cust_phone" placeholder="Customer Phone" class="form-control" value="" readonly="readonly" /> </div> <div class="form-group"> <label for="email_id"> Email </label> <input type="email" name="cust_email" placeholder="Customer Email" class="form-control" value="" readonly="readonly" /> </div> <div class="form-group"> <label for="vat_id"> V.A.T Number(ie:MT20343324) </label> <input type="text" name="cust_vat" placeholder="V.A.T Number" class="form-control" value="" readonly="readonly" /> </div> <div class="form-group"> <label for="due_date_id"> Due Date * </label> <div class="form-inline well"> <div class="input-append date" id="dp3" data-date="12-02-2012" data-date-format="dd-mm-yyyy"> <input name="due_date" class="form-control" size="25" type="text" id="dp1" value="12-02-2012"> <span class="add-on"><i class="icon-th"></i></span> </div> </div> </div> <script> $('#dp1').datepicker({ format: 'dd-mm-yyyy' }); </script> <?php //Query all the prices $query_field2 = "SELECT * FROM products ORDER BY name desc"; $result_field2 = mysqli_query($connection, $query_field2) or die (mysqli_error()); $choose_product_id = 0; $action_id = 0; $products_id = 0; $label_id = 0; $quantity = 0; while($row_field2 = mysqli_fetch_array($result_field2)){ $name = htmlspecialchars($row_field2['name']); $price1 = $row_field2['price1']; $price2 = $row_field2['price2']; $price3 = $row_field2['price3']; ?> <div class="form-inline well"> <label for="<?php echo "label".++$label_id; ?>">Choose Product <?php echo ++$choose_product_id; ?></label> <div class="form-group"> <!--Product name Select--> <select name="<?php echo "action".++$action_id; ?>" class="form-control products" id="<?php echo "products".++$products_id; ?>"> <?php $query_field3 = "SELECT * FROM products ORDER BY name desc"; $result_field3 = mysqli_query($connection, $query_field3) or die (mysqli_error()); while($row_field3 = mysqli_fetch_array($result_field3)){ $product_name = htmlspecialchars($row_field3['name']); $product_price1 = htmlspecialchars($row_field3['price1']); $product_price2 = htmlspecialchars($row_field3['price2']); $product_price3 = htmlspecialchars($row_field3['price3']); ?> <option value="<?php echo $product_name; ?>" data-product_price1="<?php echo $product_price1; ?>" data-product_price2="<?php echo $product_price2; ?>" data-product_price3="<?php echo $product_price3; ?>"><?php echo $product_name; ?></option> <?php } ?> </select> <!--Price Select--> <select name="<?php echo "action".++$number2; ?>" class="form-control"> <option id="price1"></option> <option id="price2"></option> <option id="price3"></option> </select> <label for="product1_id">Qty</label> <input name="<?php echo "quantity".++$quantity; ?>" type="text" class="form-control" maxlength="4" size="4" id="<?php echo "quantity".$quantity; ?>"> </div> </div> <?php } ?> <div class="form-inline well text-center"> <button type="submit" name="submit" class="btn btn-success btn-lg"> Create Order </button> </div> </div> </form> </div> </div> </div> </div> </div> <!-- <script> $("#products").change(function() { $("#product_prices").load("getter.php?choice=" + $("#products").val()); }); </script> --> <script> $('#cust_company_id').change(function() { selectedOption = $('option:selected', this); $('textarea[name=cust_address]').val( selectedOption.data('address') ); $('input[name=cust_name]').val( selectedOption.data('name') ); $('input[name=cust_surname]').val( selectedOption.data('surname') ); $('input[name=cust_phone]').val( selectedOption.data('phone') ); $('input[name=cust_email]').val( selectedOption.data('email') ); $('input[name=cust_vat]').val( selectedOption.data('vat') ); }); </script> <script> $(".products").change(function() { selectedOption = $(this).find(":selected"); $(this).next().children().each(function(idx){ var num=idx+1; $(this).text( selectedOption.data('product_price'+num)); }); </script> I have the dropdowns populated correctly but the jquery code that read the first drop down menu is not pulling the second dropdown menu. I have also modified my code to make it simpler for me to understand. I have also added more dynamic ids in my code as it was full of mistakes. This is the last part of my problem, after that, all good...... I have removed the radios and added 2 dropdown menu instead.
  19. Hi Requinx, What I did actually is do a rawurlencode() in the php output and this worked perfectly:-) Thank you! Ben
  20. Hello, I am a bit lost on this one, still new PHP.... I am trying to follow this tutorial here using the PHP/mysqli method: https://css-tricks.com/dynamic-dropdowns/ I am having a real problem, everything is connected and seems to be passing data to the "get" request as I see it in the console but my database data has spaces and it looks like the GET method only takes the first word. ie: This <script> $("#products").change(function() { $("#product_prices").load("getter.php?choice=" + $("#products").val());});</script> Results in this in the console: Uncaught Error: Syntax error, unrecognized expression: Bases 30cm (320gr)ga.error @ jquery.min.js:2ga.tokenize @ jquery.min.js:2ga @ jquery.min.js:2n.fn.extend.find @ jquery.min.js:2(anonymous function) @ jquery.min.js:4n.Callbacks.j @ jquery.min.js:2n.Callbacks.k.fireWith @ jquery.min.js:2x @ jquery.min.js:4n.ajaxTransport.k.cors.a.crossDomain.send.b @ jquery.min.js:4jquery.min.js:4 XHR finished loading: GET "http://site.com/admin/crud/orders/getter.php?choice=Pizza". But the data that should be pulled from the database is: Pizza Bases 30cm (230gr) (with bracket and spaces) But the GET is only taking the first word "pizza" Any idea why please? Here is the full code: Index.php <?php ob_start(); session_start(); $admin_permission = $_SESSION['admin_permission']; if(($admin_permission) == 1){ //Session admin ID equal 1 }else{ header('Location: http://' . $_SERVER['HTTP_HOST'] . '/index.php'); exit(); } ?> <?php include($_SERVER["DOCUMENT_ROOT"] . "/admin/includes/admin-header.php"); ?> <!--Content--> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <div class="row"> <div class="col-md-3"> </div> <div class="col-md-6"> <h3> Create an Order </h3> <?php // detect form submission if (isset($_POST['submit'])) { // set default values using ternary operator // boolean_test ? value_if_true : value_if_false //It means if $_POST['username'] isset "set it to" $_POST['username'] "or set it to" to "empty" $name = isset($_POST['name']) ? $_POST['name'] : ""; $surname = isset($_POST['surname']) ? $_POST['surname'] : ""; $company = isset($_POST['company']) ? $_POST['company'] : ""; $address = isset($_POST['address']) ? $_POST['address'] : ""; $phone = isset($_POST['phone']) ? $_POST['phone'] : ""; $email = isset($_POST['email']) ? $_POST['email'] : ""; $vat = isset($_POST['vat']) ? $_POST['vat'] : ""; // Escape all strings $name = mysqli_real_escape_string($connection, $name); $surname = mysqli_real_escape_string($connection, $surname); $company = mysqli_real_escape_string($connection, $company); $address = mysqli_real_escape_string($connection, $address); $phone = mysqli_real_escape_string($connection, $phone); $email = mysqli_real_escape_string($connection, $email); $vat = mysqli_real_escape_string($connection, $vat); // 2. Perform database query $query = "INSERT INTO customers (cust_name,cust_surname,cust_company,cust_address,cust_phone,cust_email,cust_vat) VALUES ('{$name}','{$surname}','{$company}','{$address}','{$phone}','{$email}','{$vat}')"; $result = mysqli_query($connection, $query); if ($result) { // Success header("Location: list-customers.php"); } else { // Failure // $message = "Subject creation failed"; die("Database query failed. " . mysqli_error($connection)); header("Location: index.php"); } } else { $name = ""; $surname = ""; $company = ""; $address = ""; $phone = ""; $email = ""; $vat = ""; } ?> <?php $random_number = rand(999 ,99999999999 ); /* $str will now be a string with the value "Glue This Into A String Please" */ ?> <form role="form" method="post" action="index.php"> <div class="form-group"> <label for="order_id"> Order ID </label> <input type="text" name="cust_order_id" class="form-control" value="<?php echo "FP" .$random_number; ?>" readonly="readonly" /> </div> <div class="form-group"> <label for="name_id"> Company * </label> <select name="cust_company" class="form-control" id="cust_company_id"> <?php $query_field1 = "SELECT * FROM customers ORDER BY cust_company desc"; $result_field1 = mysqli_query($connection, $query_field1) or die (mysqli_error()); while($row_field1 = mysqli_fetch_array($result_field1)){ $cust_name = htmlspecialchars($row_field1['cust_name']); $cust_surname = htmlspecialchars($row_field1['cust_surname']); $cust_company = htmlspecialchars($row_field1['cust_company']); $cust_address = htmlspecialchars($row_field1['cust_address']); $cust_phone = htmlspecialchars($row_field1['cust_phone']); $cust_email = htmlspecialchars($row_field1['cust_email']); $cust_vat = htmlspecialchars($row_field1['cust_vat']); ?> <option value="<?php echo $cust_company; ?>" data-name="<?php echo $cust_name; ?>" data-surname="<?php echo $cust_surname; ?>" data-address="<?php echo $cust_address; ?>" data-phone="<?php echo $cust_phone; ?>" data-email="<?php echo $cust_email; ?>" data-vat="<?php echo $cust_vat; ?>"><?php echo $cust_company; ?></option> <?php } ?> </select> </div> <div class="form-group"> <label for="address_id"> Address * </label> <textarea name="cust_address" placeholder="Company's Address" rows="4" cols="50" class="form-control" readonly="readonly" ></textarea> </div> <div class="form-group"> <label for="name_id"> Name * </label> <input type="text" name="cust_name" placeholder="Customer Name" class="form-control" value="" readonly="readonly" /> </div> <div class="form-group"> <label for="surname_id"> Surname * </label> <input type="text" name="cust_surname" placeholder="Customer Surname" class="form-control" value="" readonly="readonly" /> </div> <div class="form-group"> <label for="phone_id"> Phone </label> <input type="text" name="cust_phone" placeholder="Customer Phone" class="form-control" value="" readonly="readonly" /> </div> <div class="form-group"> <label for="email_id"> Email </label> <input type="email" name="cust_email" placeholder="Customer Email" class="form-control" value="" readonly="readonly" /> </div> <div class="form-group"> <label for="vat_id"> V.A.T Number(ie:MT20343324) </label> <input type="text" name="cust_vat" placeholder="V.A.T Number" class="form-control" value="" readonly="readonly" /> </div> <div class="form-group"> <label for="due_date_id"> Due Date * </label> <div class="form-inline well"> <div class="input-append date" id="dp3" data-date="12-02-2012" data-date-format="dd-mm-yyyy"> <input name="due_date" class="form-control" size="25" type="text" id="dp1" value="12-02-2012"> <span class="add-on"><i class="icon-th"></i></span> </div> </div> </div> <script> $('#dp1').datepicker({ format: 'dd-mm-yyyy' }); </script> <?php //Query all the prices $query_field2 = "SELECT * FROM products ORDER BY name desc"; $result_field2 = mysqli_query($connection, $query_field2) or die (mysqli_error()); $number1 = 0; $number2 = 0; $quantity = 0; while($row_field2 = mysqli_fetch_array($result_field2)){ $name = htmlspecialchars($row_field2['name']); $price1 = htmlspecialchars($row_field2['price1']); $price2 = htmlspecialchars($row_field2['price2']); $price3 = htmlspecialchars($row_field2['price3']); ?> <div class="form-inline well"> <label for="product1_id">Choose Product <?php echo ++$number1; ?></label> <div class="form-group"> <!--Product name Select--> <select name="<?php echo "action".++$number2; ?>" class="form-control" id="products"> <?php $query_field3 = "SELECT * FROM products ORDER BY name desc"; $result_field3 = mysqli_query($connection, $query_field3) or die (mysqli_error()); while($row_field3 = mysqli_fetch_array($result_field3)){ $product_name = htmlspecialchars($row_field3['name']); $product_price1 = htmlspecialchars($row_field3['price1']); $product_price2 = htmlspecialchars($row_field3['price2']); $product_price3 = htmlspecialchars($row_field3['price3']); ?> <option value="<?php echo $product_name; ?>" data-product_price1="<?php echo $product_price1; ?>" data-product_price2="<?php echo $product_price2; ?>" data-product_price3="<?php echo $product_price3; ?>"><?php echo $product_name; ?></option> <?php } ?> </select> <!--Price Select--> <select name="<?php echo "action".++$number2; ?>" class="form-control" id="product_prices"> <option>Select the price</option> </select> <label for="product1_id">Qty</label> <input name="<?php echo "quantity".++$quantity; ?>" type="text" class="form-control" maxlength="4" size="4" id="<?php echo "quantity".$quantity; ?>"> </div> </div> <?php } ?> <div class="form-inline well text-center"> <button type="submit" name="submit" class="btn btn-success btn-lg"> Create Order </button> </div> </div> </form> </div> </div> </div> </div> </div> <script> $("#products").change(function() { $("#product_prices").load("getter.php?choice=" + $("#products").val()); }); </script> <script> $('#cust_company_id').change(function() { selectedOption = $('option:selected', this); $('textarea[name=cust_address]').val( selectedOption.data('address') ); $('input[name=cust_name]').val( selectedOption.data('name') ); $('input[name=cust_surname]').val( selectedOption.data('surname') ); $('input[name=cust_phone]').val( selectedOption.data('phone') ); $('input[name=cust_email]').val( selectedOption.data('email') ); $('input[name=cust_vat]').val( selectedOption.data('vat') ); }); </script> <!--Content--> <?php // 5. Close database connection if(isset($connection)){ mysqli_close($connection);} ob_flush(); ?> <?php include($_SERVER["DOCUMENT_ROOT"] . "/admin/includes/admin-footer.php"); ?> And here is the Getter.php <?php $choice = mysqli_real_escape_string($connection, $_GET['choice']); $query = "SELECT price1 FROM products WHERE name='$choice'"; $result = mysqli_query($connection, $query); while ($row = mysqli_fetch_array($result)) { echo "<option>" . $row['price1'] . "</option>"; } ?> I am also just found out that only the first dropdown menu is initiating the getter.php search and not the others....still trying to figure out why.
  21. Hello, Here is my code, I am getting the error: Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\food\admin\crud\orders\index.php on line 97 This line corresponds to foreach( $product_name as $key => $n ) { I am not understanding why the $product_name is not working. Normally you should get a form with one product per line, front of each product, 3 prices. I am trying to get all the dynamic info from the generated field into an $_POST but I struggle.... <?php ob_start();session_start();$admin_permission = $_SESSION['admin_permission'];if(($admin_permission) == 1){//Session admin ID equal 1}else{header('Location: http://' . $_SERVER['HTTP_HOST'] . '/index.php');exit();}?><?php include($_SERVER["DOCUMENT_ROOT"] . "/admin/includes/admin-header.php"); ?> <!--Content--> <div class="container-fluid"><div class="row"><div class="col-md-12"><div class="row"><div class="col-md-3"></div><div class="col-md-6"><h3>Create an Order</h3> <?php // detect form submissionif (isset($_POST['submit'])) {// set default values using ternary operator// boolean_test ? value_if_true : value_if_false//It means if $_POST['username'] isset "set it to" $_POST['username'] "or set it to" to "empty"$name = isset($_POST['name']) ? $_POST['name'] : "";$surname = isset($_POST['surname']) ? $_POST['surname'] : "";$company = isset($_POST['company']) ? $_POST['company'] : ""; $address = isset($_POST['address']) ? $_POST['address'] : "";$phone = isset($_POST['phone']) ? $_POST['phone'] : "";$email = isset($_POST['email']) ? $_POST['email'] : "";$vat = isset($_POST['vat']) ? $_POST['vat'] : ""; // Escape all strings $name = mysqli_real_escape_string($connection, $name);$surname = mysqli_real_escape_string($connection, $surname);$company = mysqli_real_escape_string($connection, $company);$address = mysqli_real_escape_string($connection, $address);$phone = mysqli_real_escape_string($connection, $phone);$email = mysqli_real_escape_string($connection, $email);$vat = mysqli_real_escape_string($connection, $vat); // 2. Perform database query $query = "INSERT INTO customers (cust_name,cust_surname,cust_company,cust_address,cust_phone,cust_email,cust_vat) VALUES ('{$name}','{$surname}','{$company}','{$address}','{$phone}','{$email}','{$vat}')"; $result = mysqli_query($connection, $query); if ($result) {// Success header("Location: list-customers.php"); } else {// Failure// $message = "Subject creation failed";die("Database query failed. " . mysqli_error($connection));header("Location: index.php"); } } else {$name = "";$surname = "";$company = "";$address = "";$phone = "";$email = "";$vat = "";}?> <?php $random_number = rand(999 ,99999999999 );/* $str will now be a string with the value "Glue This Into A String Please" */ ?> <?php $_POST['product_name'] = ""; $_POST['product_price'] = "";$product_name = $_POST['product_name']; $product_price = $_POST['product_price']; foreach( $product_name as $key => $n ) { print "The product name is ".$n." and the price 1 is ".$product_price1[$key]."\n"; }?> <form role="form" method="post" action="index.php"> <div class="form-group"><label for="order_id">Order ID</label><input type="text" name="cust_order_id" class="form-control" value="<?php echo "FP" .$random_number; ?>" readonly="readonly" /></div> <div class="form-group"><label for="name_id">Company *</label> <select name="cust_company" class="form-control" id="cust_company_id"> <?php $query_field1 = "SELECT * FROM customers ORDER BY cust_company desc"; $result_field1 = mysqli_query($connection, $query_field1) or die (mysqli_error());$number1 = 0; $number2 = 0; $number3 = 0; while($row_field1 = mysqli_fetch_array($result_field1)){$cust_name = htmlspecialchars($row_field1['cust_name']);$cust_surname = htmlspecialchars($row_field1['cust_surname']);$cust_company = htmlspecialchars($row_field1['cust_company']); $cust_address = htmlspecialchars($row_field1['cust_address']); $cust_phone = htmlspecialchars($row_field1['cust_phone']); $cust_email = htmlspecialchars($row_field1['cust_email']); $cust_vat = htmlspecialchars($row_field1['cust_vat']);?> <option value="<?php echo $cust_company; ?>" data-name="<?php echo $cust_name; ?>" data-surname="<?php echo $cust_surname; ?>" data-address="<?php echo $cust_address; ?>" data-phone="<?php echo $cust_phone; ?>" data-email="<?php echo $cust_email; ?>" data-vat="<?php echo $cust_vat; ?>"><?php echo $cust_company; ?></option> <?php } ?> </select> </div> <div class="form-group"><label for="address_id">Address *</label><textarea name="cust_address" placeholder="Company's Address" rows="4" cols="50" class="form-control" readonly="readonly" ></textarea></div> <div class="form-group"><label for="name_id">Name *</label><input type="text" name="cust_name" placeholder="Customer Name" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="surname_id">Surname *</label><input type="text" name="cust_surname" placeholder="Customer Surname" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="phone_id">Phone</label><input type="text" name="cust_phone" placeholder="Customer Phone" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="email_id">Email</label><input type="email" name="cust_email" placeholder="Customer Email" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="vat_id">V.A.T Number(ie:MT20343324)</label><input type="text" name="cust_vat" placeholder="V.A.T Number" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="due_date_id">Due Date *</label><div class="form-inline well"> <div class="input-append date" id="dp3" data-date="12-02-2012" data-date-format="dd-mm-yyyy"> <input name="due_date" class="form-control" size="25" type="text" id="dp1" value="12-02-2012"> <span class="add-on"><i class="icon-th"></i></span></div> </div> </div> <script>$('#dp1').datepicker({ format: 'dd-mm-yyyy' });</script> <?php //Query all the prices $query_field2 = "SELECT * FROM products ORDER BY name desc"; $result_field2 = mysqli_query($connection, $query_field2) or die (mysqli_error());$id_1 = 0;$id_2 = 0;$id_3 = 0;$quantity = 0; while($row_field2 = mysqli_fetch_array($result_field2)){$name = htmlspecialchars($row_field2['name']);$price1 = htmlspecialchars($row_field2['price1']);$price2 = htmlspecialchars($row_field2['price2']);$price3 = htmlspecialchars($row_field2['price3']); ?><div class="form-inline well"><label for="product1_id">Choose Product <?php echo ++$number1; ?></label><div class="form-group"> <input name="product_name" type="text" class="form-control" value="<?php echo $name; ?>" disabled> <!--Price 1--> <label class="btn btn-default"> <input type="radio" name="product_price" value="<?php echo $price1;?>" id="<?php echo ++$id_1; ?>" />€ <?php echo $price1; ?> </label> <!--Price 1--> <!--Price 2--> <?php //Do not show second price if not setif(($price2) != null) {echo "<label class=\"btn btn-default\"> <input type=\"radio\" name=\"product_price\" value=\"{$price2}\" id=\"".(++$id_2)."\" /> € {$price2} </label>";} ?> <!--Price 2--> <!--Price 3--> <?php //Do not show third price if not setif(($price3) != null) {echo "<label class=\"btn btn-default\"> <input type=\"radio\" name=\"product_price\" value=\"{$price3}\" id=\"".(++$id_3)."\" /> € {$price3} </label>";} ?> <!--Price 3--> <label for="product1_id">Qty</label><input name="<?php echo "quantity".++$quantity; ?>" type="text" class="form-control" maxlength="4" size="4"> </div> </div><?php } ?> <div class="form-inline well text-center"><button type="submit" name="submit" class="btn btn-success btn-lg">Create Order</button></div></div> </form> </div> </div></div></div></div> <script> $('#cust_company_id').change(function() { selectedOption = $('option:selected', this); $('textarea[name=cust_address]').val( selectedOption.data('address') );$('input[name=cust_name]').val( selectedOption.data('name') );$('input[name=cust_surname]').val( selectedOption.data('surname') ); $('input[name=cust_phone]').val( selectedOption.data('phone') ); $('input[name=cust_email]').val( selectedOption.data('email') ); $('input[name=cust_vat]').val( selectedOption.data('vat') );}); </script> <!--Content--><?php // 5. Close database connection if(isset($connection)){ mysqli_close($connection);} ob_flush();?> <?php include($_SERVER["DOCUMENT_ROOT"] . "/admin/includes/admin-footer.php"); ?>
  22. Mac_Gyver, I cannot do that. Each product has 3 price(3 types of clients). So product1 = Price1[radio], Price2[radio], Price3[radio] product2 = Price1[radio], Price2[radio], Price3[radio] product3 = Price1[radio], Price2[radio], Price3[radio] And so on... I have now managed to generate all my "names" and ids dynamically but I was Looking at the first solution of CyberRobt, I am not sure this will work with 3 prices per product, or will it? I have this now: <?php $random_number = rand(999 ,99999999999 ); ?> <form role="form" method="post" action="index.php"> <div class="form-group"><label for="order_id">Order ID</label><input type="text" name="cust_order_id" class="form-control" value="<?php echo "FP" .$random_number; ?>" readonly="readonly" /></div> <div class="form-group"><label for="name_id">Company *</label> <select name="cust_company" class="form-control" id="cust_company_id"> <?php $query_field1 = "SELECT * FROM customers ORDER BY cust_company desc"; $result_field1 = mysqli_query($connection, $query_field1) or die (mysqli_error()); $number1 = 0; $number2 = 0; $number3 = 0; while($row_field1 = mysqli_fetch_array($result_field1)){ $cust_name = htmlspecialchars($row_field1['cust_name']); $cust_surname = htmlspecialchars($row_field1['cust_surname']); $cust_company = htmlspecialchars($row_field1['cust_company']); $cust_address = htmlspecialchars($row_field1['cust_address']); $cust_phone = htmlspecialchars($row_field1['cust_phone']); $cust_email = htmlspecialchars($row_field1['cust_email']); $cust_vat = htmlspecialchars($row_field1['cust_vat']);?> <option value="<?php echo $cust_company; ?>" data-name="<?php echo $cust_name; ?>" data-surname="<?php echo $cust_surname; ?>" data-address="<?php echo $cust_address; ?>" data-phone="<?php echo $cust_phone; ?>" data-email="<?php echo $cust_email; ?>" data-vat="<?php echo $cust_vat; ?>"><?php echo $cust_company; ?></option> <?php } ?> </select> </div> <div class="form-group"><label for="address_id">Address *</label><textarea name="cust_address" placeholder="Company's Address" rows="4" cols="50" class="form-control" readonly="readonly" ></textarea></div> <div class="form-group"><label for="name_id">Name *</label><input type="text" name="cust_name" placeholder="Customer Name" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="surname_id">Surname *</label><input type="text" name="cust_surname" placeholder="Customer Surname" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="phone_id">Phone</label><input type="text" name="cust_phone" placeholder="Customer Phone" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="email_id">Email</label><input type="email" name="cust_email" placeholder="Customer Email" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="vat_id">V.A.T Number(ie:MT20343324)</label><input type="text" name="cust_vat" placeholder="V.A.T Number" class="form-control" value="" readonly="readonly" /></div> <div class="form-group"><label for="due_date_id">Due Date *</label><div class="form-inline well"> <div class="input-append date" id="dp3" data-date="12-02-2012" data-date-format="dd-mm-yyyy"> <input name="due_date" class="form-control" size="25" type="text" id="dp1" value="12-02-2012"> <span class="add-on"><i class="icon-th"></i></span></div> </div> </div> <script>$('#dp1').datepicker({ format: 'dd-mm-yyyy' });</script> <?php //Query all the prices $query_field2 = "SELECT * FROM products ORDER BY name desc"; $result_field2 = mysqli_query($connection, $query_field2) or die (mysqli_error()); $number1 = 0; $number2 = 0; $number3 = 0; $id_1 = 0; $id_2 = 0; $id_3 = 0; $quantity = 0; while($row_field2 = mysqli_fetch_array($result_field2)){$name = htmlspecialchars($row_field2['name']);$price1 = htmlspecialchars($row_field2['price1']);$price2 = htmlspecialchars($row_field2['price2']);$price3 = htmlspecialchars($row_field2['price3']); ?><div class="form-inline well"><label for="product1_id">Choose Product <?php echo ++$number1; ?></label><div class="form-group"> <input name="<?php echo "product".++$number2; ?>" type="text" class="form-control" value="<?php echo $name; ?>" disabled> <!--Price 1--> <label class="btn btn-default"> <input type="radio" name="<?php echo "action".++$number3; ?>" value="<?php echo $price1;?>" id="<?php echo ++$id_1; ?>" />€ <?php echo $price1; ?> </label> <!--Price 1--> <!--Price 2--> <?php //Do not show second price if not setif(($price2) != null) {echo "<label class=\"btn btn-default\"> <input type=\"radio\" name=\"action".($number3)."\" value=\"{$price2}\" id=\"".(++$id_2)."\" /> € {$price2} </label>";} ?> <!--Price 2--> <!--Price 3--> <?php //Do not show third price if not setif(($price3) != null) {echo "<label class=\"btn btn-default\"> <input type=\"radio\" name=\"action{$number3}\" value=\"{$price3}\" id=\"".(++$id_3)."\" /> € {$price3} </label>";} ?> <!--Price 3--> <label for="product1_id">Qty</label><input name="<?php echo "quantity".++$quantity; ?>" type="text" class="form-control" maxlength="4" size="4"> </div> </div> <?php } ?> <div class="form-inline well text-center"><button type="submit" name="submit" class="btn btn-success btn-lg">Create Order</button></div></div> </form> </div> </div></div></div></div> <script> $('#cust_company_id').change(function() { selectedOption = $('option:selected', this); $('textarea[name=cust_address]').val( selectedOption.data('address') ); $('input[name=cust_name]').val( selectedOption.data('name') ); $('input[name=cust_surname]').val( selectedOption.data('surname') ); $('input[name=cust_phone]').val( selectedOption.data('phone') ); $('input[name=cust_email]').val( selectedOption.data('email') ); $('input[name=cust_vat]').val( selectedOption.data('vat') );}); </script>
  23. My apology, I have just seen your reply now.......thank you so much. Yes the double incremental is a mistake which I forgot to remove before posting...sorry. This was so simple about the echo....dang! Thank you so much!!! Ben
×
×
  • 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.