newbie_kerry Posted June 23, 2012 Share Posted June 23, 2012 I am wanting to have a code "discount10" to give 10% off all purchases I have created the tables, but unsure what code to do next. Here is my basket, where I want the code to be: Link to comment Share on other sites More sharing options...
Larry Posted June 26, 2012 Share Posted June 26, 2012 Would probably help to know how the table is set up. But I'm fairly sure you don't want to select everything from the discount_codes table. Link to comment Share on other sites More sharing options...
newbie_kerry Posted June 26, 2012 Author Share Posted June 26, 2012 It is a fairly basic table as per the other tables in your book. It is containing: discount_id: int(11) discount_code: varchar(25) discount_amount I just selected select all from table so I was not missing something. I am unsure how to script the voucher discount to read the discount entered by the customer in the form. Link to comment Share on other sites More sharing options...
margaux Posted June 26, 2012 Share Posted June 26, 2012 You can use the variable you created from $_GET, although you might want to do some validation on it first. SELECT discount_amount FROM discount_codes WHERE discount_code = '$vouchercode'; Link to comment Share on other sites More sharing options...
newbie_kerry Posted June 26, 2012 Author Share Posted June 26, 2012 SELECT Link to comment Share on other sites More sharing options...
margaux Posted June 26, 2012 Share Posted June 26, 2012 This is a bit confusing. What is the tablename? Your select statement should be in the format of SELECT columnname FROM tablename WHERE columnname = '$variable' Assuming your table is named discount_codes and the column is named vouchercode... SELECT discount_amount FROM discount_codes WHERE vouchercode = '$vouchercode' Run your mysql statements in something like phpmyadmin and if it doesn't work it will give you a message to indicate where the error is. Then in your posts you can be more specific rather than just stating it doesn't work, which doesn't actually give any information. I would recommend reading chap 5 and chap 8. Link to comment Share on other sites More sharing options...
newbie_kerry Posted June 26, 2012 Author Share Posted June 26, 2012 $q = "SELECT discount_amount FROM discount_codes WHERE vouchercode = '$vouchercode'"; Link to comment Share on other sites More sharing options...
Recommended Posts